Created
July 5, 2012 13:42
-
-
Save misfo/3053737 to your computer and use it in GitHub Desktop.
When was Yale's 483rd reunion?
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 reunions.core) | |
| (defn- next-year | |
| [years reunion-counts] | |
| (let [this-year (inc (last (keys reunion-counts))) | |
| reunion-counts (assoc reunion-counts this-year 0) | |
| add-reunion (fn [counts year] | |
| (let [abs-year (- this-year year)] | |
| (if (contains? counts abs-year) | |
| (update-in counts [abs-year] inc) | |
| counts)))] | |
| (reduce add-reunion reunion-counts years))) | |
| (defn reunions | |
| [year-established years] | |
| (iterate (partial next-year years) | |
| (sorted-map year-established 0))) | |
| (defn when-was-yales-483rd-reunion? | |
| [years] | |
| (last (keys (first (filter #(>= (apply + (vals %)) 483) | |
| (reunions 1701 years)))))) | |
| ; (core/when-was-yales-483rd-reunion? #{5 10 20}) | |
| ;=> 1873 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment