Skip to content

Instantly share code, notes, and snippets.

@zc00gii
Created June 26, 2010 14:11
Show Gist options
  • Save zc00gii/454077 to your computer and use it in GitHub Desktop.
Save zc00gii/454077 to your computer and use it in GitHub Desktop.
(defun pythagorean (a b)
"Find the 3rd line in a right angle. a^2 + b^2 = c^2 and a > c > b"
(declare (real a b))
(if (> a b) 'f
(sqrt (+ (expt a 2) (expt b 2)))))
(defun reverse-pythagorean (c b)
"Reverse of `pythagorean' c^2 - b^2 = a^2 and c < b < a"
(declare (real b c))
(if (> b c) 'f
(sqrt (- (expt c 2) (expt b 2)))))
(defun pythagoreanp (a b c)
"Returns t or nil if it's a correct pythagorean or not."
(declare (real a b c))
(and (> a b) (> b c) = (pythagorean a b) c) (= (reverse-pythagorean c b) a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment