Created
October 12, 2010 09:48
-
-
Save rlorca/621941 to your computer and use it in GitHub Desktop.
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
;exercise from http://programmingpraxis.com/2010/10/08/zellers-congruence/ | |
;formula from http://en.wikipedia.org/wiki/Zeller%27s_congruence | |
(defn month-id [month] | |
(+ 3 | |
(mod (+ month 9) 12))) | |
(defn year-of-century [year] | |
(mod year 100)) | |
(defn century [year] | |
(quot year 100)) | |
(defn int-week-day [day month year] | |
(let [q day | |
m (month-id month) | |
k (year-of-century year) | |
j (century year)] | |
(mod | |
(+ q | |
(quot (* (+ m 1) 26) 10) | |
k | |
(quot k 4) | |
(quot j 4) | |
(- (* 2 j))) | |
7))) | |
(defn week-day [day month year] | |
(+ 1 | |
(mod | |
(+ 5 (int-week-day day month year)) | |
7))) | |
;usage (week-day 12 10 2010) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment