Skip to content

Instantly share code, notes, and snippets.

@samccone
Last active August 29, 2015 14:21
Show Gist options
  • Save samccone/db7e7acddea841916a79 to your computer and use it in GitHub Desktop.
Save samccone/db7e7acddea841916a79 to your computer and use it in GitHub Desktop.
squared_same
(defn squared_same [a b]
(cond
; handle nil case
(or (nil? a) (nil? b)) false
; make sure the number of unique elements lines up
(not= (count (distinct a)) (count (distinct b))) false
; loop over each element of (doubled)
; if a is not present in b eager exit
; nil? is to invert the some return value to match
; the defined sped.
:else (nil? (some (fn [v] (= -1 (.indexOf b v)))
(map #(* % %) a)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment