Last active
April 6, 2016 21:24
-
-
Save joshrotenberg/cde54ecb40db45acc7b31c995e83edc4 to your computer and use it in GitHub Desktop.
code golfing a clojure function to determine if two numbers are opposite (1 and -1, for example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn opposite? | |
"Returns true if x and y are opposite numbers, false otherwise." | |
[x y] | |
(and (zero? (+ x y)) | |
(every? (complement zero?) [x y]))) | |
(= true (opposite? 1 -1)) | |
(= true (opposite? 0.27 -0.27)) | |
(= false (opposite? -1 2)) | |
(= false (opposite? -2 -2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment