Skip to content

Instantly share code, notes, and snippets.

@jaidetree
Last active December 1, 2020 08:25
Show Gist options
  • Save jaidetree/746de05c2d9f82a8bf8a5685c932cce7 to your computer and use it in GitHub Desktop.
Save jaidetree/746de05c2d9f82a8bf8a5685c932cce7 to your computer and use it in GitHub Desktop.
2020 Advent of Code
(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