Skip to content

Instantly share code, notes, and snippets.

@rlorca
Created October 12, 2010 09:48
Show Gist options
  • Save rlorca/621941 to your computer and use it in GitHub Desktop.
Save rlorca/621941 to your computer and use it in GitHub Desktop.
;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