Created
December 6, 2012 18:48
-
-
Save llasram/4227022 to your computer and use it in GitHub Desktop.
Project Euler problem 19 solution
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
(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