Last active
December 2, 2017 17:21
-
-
Save honzabrecka/315ce6b3838c01ab97ba0c4a4df12410 to your computer and use it in GitHub Desktop.
This file contains 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 shift | |
[[h & t]] | |
(concat t [h])) | |
(defn apply-times | |
[f n v] | |
(if (= n 0) | |
v | |
(recur f (dec n) (f v)))) | |
; part 1 | |
(let [col "1111"] | |
(transduce (comp (filter (partial apply =)) | |
(map first) | |
(map int)) | |
+ | |
(map vector col (shift col)))) | |
; part 2 | |
(let [col "1212" | |
c (count (seq col))] | |
(transduce (comp (filter (partial apply =)) | |
(map first) | |
(map int)) | |
+ | |
(map vector col (apply-times shift (/ c 2) col)))) |
This file contains 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
(let [sheet [[5 1 9 5] | |
[7 5 3] | |
[2 4 6 8]]] | |
(transduce (comp (map sort) | |
(map (juxt last first)) | |
(map (partial apply -))) | |
+ | |
sheet)) | |
(comment | |
; or juxt with min/max | |
(let [sheet [[5 1 9 5] | |
[7 5 3] | |
[2 4 6 8]]] | |
(transduce (comp (map (juxt (partial apply max) | |
(partial apply min))) | |
(map (partial apply -))) | |
+ | |
sheet))) | |
(let [sheet [[5 9 2 8] | |
[9 4 7 3] | |
[3 8 6 5]]] | |
(transduce (comp (map (fn [col] | |
(for [a col | |
b col | |
:when (and (not= a b) | |
(zero? (mod a b)))] | |
[a b]))) | |
(map first) | |
(map (partial apply /))) | |
+ | |
sheet)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment