Created
April 27, 2024 21:23
-
-
Save jsn/b0cec248603fbf47bc3a3e776917ad5b 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
(ns ab) | |
(defn- bump [f m] | |
(into {} (map (juxt (comp f key) val) m))) | |
(defn- turn [[a b]] | |
(mapv #(merge-with + b (bump % a)) [inc dec])) | |
(->> {0 1N} | |
(repeat 2) | |
(iterate turn) | |
(drop 99) | |
first | |
(apply merge-with +) | |
(group-by #(compare (key %) 0)) | |
(map (juxt (comp {1 :a -1 :b} key) #(->> % val (map peek) (apply +)))) | |
(filter first) | |
(sort-by first) | |
prn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment