Anonymous user
Special pythagorean triplet: Difference between revisions
→{{header|Common Lisp}}: Added more conventional implementation.
(→{{header|Common Lisp}}: Added Common Lisp version) |
(→{{header|Common Lisp}}: Added more conventional implementation.) |
||
Line 76:
=={{header|Common Lisp}}==
This version utilizes SCREAMER which provides constraint solving.▼
A conventional solution:
<lang lisp>
(defun special-triple (sum)
(loop
for a from 1
do (loop
for b from (1+ a)
for c = (- sum a b)
when (< c b) do (return)
when (= (* c c) (+ (* a a) (* b b)))
do (return-from conventional-triple-search (list a b c)))))
</lang>
<lang lisp>
|