pass(auckland, hamilton, bus).
pass(bangkok, auckland, plane).
pass(frankfurt, bangkok, plane).
pass(frankfurt, singapore, plane).
pass(hamilton, raglan, bus).
pass(losAngeles, auckland, plane).
pass(metz, frankfurt, train).
pass(metz, paris, train).
pass(paris, losAngeles, plane).
pass(saarbruecken, frankfurt, train).
pass(saarbruecken, paris, train).
pass(valmont, metz, bus).
pass(valmont, saarbruecken, bus).
travel(X,Y) :-
pass(X, Y, T) ->
write([T, X, Y]), ! , nl ;
pass(X, Z, T1) ,
pass(Z, Y, T2) ->
write([T1, X, Z, T2, Z, Y]), !, nl ;
pass(X, Z1, T1) ,
pass(Z1, Z2, T2) ,
pass(Z2, Y, T3) ->
write([T1, X, Z1, T2, Z1, Z2, T3, Z2, Y]), !, nl ;
pass(X, Z1, T1) ,
pass(Z1, Z2, T2) ,
pass(Z2, Z3, T3) ,
pass(Z3, Y, T4) ->
write([T1, X, Z1, T2, Z1, Z2, T3, Z2, Z3, T4, Z3, Y]), !, nl .
title
description
Wednesday, May 13, 2020
Prolog. задача о путешествии
Monday, October 31, 2016
задачка о тортике, Си и Хаскель
ВиниПух и Пятачок сьели торт за t секунд. если бы ели тот же торт два Винни–Пуха, то у них торт был бы съеден на 1 минуту раньше, а если бы тот же самый торт ели два Пятачка, то они на 4 минуты больше бы времени затратили. так за сколько же времени съели торт друзья?
сначала Винни сжирает по-быстрому свою половину, а потом еще 1 минуту они хомячат вместе то, что Пятачок в одиночку ел бы дополнительные 5 мин - т.е. _вдвоем_ Винни и Пятачок едят как _пять_ Пятачков, т.е. Винни один ест за четверых Пятачков
-- import Debug.Trace
import Control.Monad
-- import System.IO
import System.Environment
pudding :: Double -> Double -> Double
pudding t1 t2 =
head $ [1..] >>= \t -> -- traceShow t $
let p = (recip t) / 5
b = p * 4
f = \t0 v1 v2 -> guard $ 1e-8 >= (abs $ t0 * (v1 + v2) - 1)
in (f t b p) >> (f (t + t1) b b) >> (f (t + t2) p p) >> return t
main :: IO ()
main =
getEnv "vin" >>= \x -> getEnv "pig" >>= \y ->
return (pudding (read x) (read y)) >>= print
{-
(pudding <$ putStr "медведи : " <* hFlush stdout <*> readLn
<* putStr "поросята : " <* hFlush stdout <*> readLn) >>= print
getArgs >>= \args ->
if (length args == 2)
then return (pudding (read $ head args) (read $ head $ tail args)) >>= print
else putStrLn "usage: a.out two_winnies_delta two_piggies_delta"
-}
и на сях:
#include <stdlib.h>
#include <stdio.h>
int comp (float, float, float) ;
int main (int argc, char** argv, char** envp)
{
float t0 , t1 , t2 , p , b ; t0 = 60.0 ;
/* if (argc != 3)
{ printf ("usage: two_winnies_delta two_piggies_delta\n") ; return 1 ; }
t0 = 0.0 ; t1 = atof (argv[1]) ; t2 = atof (argv[2]) ; */
printf ("winnies : ") ; scanf ("%f", &t1) ;
printf ("piggies : ") ; scanf ("%f", &t2) ;
while (1)
{
t0 = t0 + 1 ; p = 1 / (5 * t0) ; b = 4 * p ;
// printf ("%5.2f\n", t0) ;
if ((comp (t0, p, b) == 1) &
(comp (t0 + t1, b, b) == 1) &
(comp (t0 + t2, p, p) == 1)) break ;
}
printf ("%5.2f\n", t0) ;
return 0 ;
}
int comp (float t0, float t1, float t2)
{
if ((t0 * (t1 + t2) - 1.0) < 0.00000001) return 1 ; else return 0 ;
}
Friday, October 14, 2016
Идрис 02
Double
sqrt : Double -> Double
exp : Double -> Double
log : Double -> Double
ceiling : Double -> Double
floor : Double -> Double
euler : Double
pi : Double
cos : Double -> Double
sin : Double -> Double
tan : Double -> Double
acos : Double -> Double
asin : Double -> Double
atan : Double -> Double
cosh : Double -> Double
sinh : Double -> Double
tanh : Double -> Double
one step
the difficulty of the manufacture of a large cylinder with a tightly fitting piston was solved by John Wilkinson. Watt also adapted his engine to produce rotary motion, greatly broadening its use beyond pumping water. in 1776, the first engines were installed and working in commercial enterprises
Tuesday, September 27, 2016
Идрис 01
comments
-- single-line {- multi-line -}
keywords
case .. of constructor data export if .. then .. else .. implementation import interface let .. in module mutual namespace parameters private public export record total using where
primitive types:
Int Integer Double Char String Bool : True | False Ptr Bits8 Bits16 Bits32 Bits64
ops
Sunday, June 17, 2012
two steps
The "Flyer" lifted from level ground to the north of Big Kill Devil Hill, North Carolina, at 10:35 a.m., on December 17, 1903. Orville Wright piloted the plane which weighed six hundred and five pounds. The first heavier-than-air, controlled, powered and sustained flight traveled one hundred twenty feet in twelve seconds
Wednesday, June 6, 2012
three steps
16 July 1945 at 05:29:45 local time (Trinity Site, Socorro, New Mexico) the device Gadget exploded with an energy equivalent to around 20 kilotons of TNT. it left a crater of radioactive glass in the desert 3 m deep and 330 m wide. the shock wave was felt over 160 km away, and the mushroom cloud reached 12 km in height
Electronic Numerical Integrator And Calculator was completed in 1946 (University of Pennsylvania). it occupied about 200 m2, used 17468 vacuum tubes, 15000 relays, weighing almost 50 tons and consuming 200 Kilowatts of electricity. it boasted speeds one thousand times faster than electro-mechanical machines