Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Last active April 6, 2016 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshrotenberg/cde54ecb40db45acc7b31c995e83edc4 to your computer and use it in GitHub Desktop.
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)
(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