Skip to content

Instantly share code, notes, and snippets.

@llasram
Created December 6, 2012 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llasram/4227022 to your computer and use it in GitHub Desktop.
Save llasram/4227022 to your computer and use it in GitHub Desktop.
Project Euler problem 19 solution
(defn p19-solution []
(let [multiple? #(zero? (rem %1 %2))
leap-year? #(or (and (multiple? % 4)
(not (multiple? % 100)))
(multiple? % 400))
february #(if (leap-year? %) 29 28)
mdays [31 28 31 30 31 30 31 31 30 31 30 31]
mdays (map #(constantly %) mdays)
mdays (apply juxt (assoc (vec mdays) 1 february))
months (mapcat mdays (range 1901 2001))
days1900 (reduce + (mdays 1900))
sunday? #(= 6 (rem % 7))]
(first
(reduce (fn [[n d] m]
[(if (sunday? d) (inc n) n) (+ d m)])
[0 days1900]
months))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment