Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fuck yeah, Prolog!

Name: Anonymous 2008-09-09 17:27

good-enough(Guess, Value) :- abs(Guess**2 - Value) < 0.000001 .

improve-guess(Guess, Value, NewGuess) :- NewGuess is (Guess + (Value/Guess))/2 .

guess-root(Value, Guess, Result) :-
  good-enough(Guess, Value) -> Result is Guess;
  improve-guess(Guess, Value, NewGuess),
  guess-root(Value, NewGuess, Result).

sqrt(X, Y) :- guess-root(X, 1, Y).

Name: Anonymous 2008-09-15 0:24

>>17
So ``Q'' is basically Haskell with less sensible capitalization? How quaint.

primes       = sieve [2..]
sieve (x:xs) = x : sieve (filter (not . divBy x) xs)
divBy m n    = n `mod` m == 0

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List