Last active
August 29, 2015 14:21
-
-
Save samccone/db7e7acddea841916a79 to your computer and use it in GitHub Desktop.
squared_same
This file contains hidden or 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 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