Created
November 20, 2019 17:21
-
-
Save ynonp/4313ea81e3905f2779cdfc6dfded8190 to your computer and use it in GitHub Desktop.
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 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