Skip to content

Instantly share code, notes, and snippets.

@jsn
Created April 27, 2024 21:23
Show Gist options
  • Save jsn/b0cec248603fbf47bc3a3e776917ad5b to your computer and use it in GitHub Desktop.
Save jsn/b0cec248603fbf47bc3a3e776917ad5b to your computer and use it in GitHub Desktop.
(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