Last active
December 1, 2020 08:25
-
-
Save jaidetree/746de05c2d9f82a8bf8a5685c932cce7 to your computer and use it in GitHub Desktop.
2020 Advent of Code
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 find-sum | |
"O(n^2)" | |
[sum nums] | |
(set (for [x nums | |
y nums | |
:when (and (not= x y) | |
(= sum (+ x y)))] | |
(* x y)))) | |
(defn find-sum | |
"O(4n^2)" | |
[sum nums] | |
(->> (for [x nums y nums] | |
#{x y}) | |
(filter #(and (= (+ (first %) (second %)) sum) | |
(= 2 (count %)))) | |
(map #(* (first %) (second %))) | |
(set))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment