Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created November 20, 2019 17:21
Show Gist options
  • Save ynonp/4313ea81e3905f2779cdfc6dfded8190 to your computer and use it in GitHub Desktop.
Save ynonp/4313ea81e3905f2779cdfc6dfded8190 to your computer and use it in GitHub Desktop.
(defn power
[serial x y]
(let [
rack-id (+ x 10)
]
(-
(Math/floor
(mod
(/ (* (+ (* rack-id y) serial) rack-id) 100)
10))
5)))
(defn sum-square
[square]
(reduce + 0 (map (partial apply power) square)))
(defn max-with-size
[serial size]
(apply max-key
sum-square
(for [
x (range 1 301)
y (range 1 301)
]
(for [xx (range x (+ x size))
yy (range y (+ y size))
]
[serial xx yy]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment