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-14 7:16

Prolog is fucking zen.

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