Skip to content

Instantly share code, notes, and snippets.

@misfo
Created July 5, 2012 13:42
Show Gist options
  • Select an option

  • Save misfo/3053737 to your computer and use it in GitHub Desktop.

Select an option

Save misfo/3053737 to your computer and use it in GitHub Desktop.
When was Yale's 483rd reunion?
(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