;; @module zeller.lsp ;; @description Straightforward implementation of Zeller's congruence ;; @author Cyril Slobin ;; @location http://slobin.pp.ru/newlisp/zeller.lsp ;; @version 2.0, corrected and updated ;; ;; See also @link http://en.wikipedia.org/wiki/Zeller%27s_congruence ;; Zeller's_congruence article in Wikipedia ;; ;; Date format on input as specified by newdep, exactly ; The week starts with Saturday, it's a feature of the algorithm used (setq week '(Saturday Sunday Monday Tuesday Wednesday Thursday Friday)) ; Modulo is not the same as reminder (define (%% x y) (% (+ (% x y) y) y)) ; Division with modulo-aware rounding (define (// x y) (/ (- x (%% x y)) y)) ; Zeller's congruence, verbatim (define (zeller q m year , h J K) (when (member m '(1 2)) (inc m 12) (dec year)) (setq J (// year 100)) (setq K (%% year 100)) (setq h (+ q (// (* 26 (+ m 1)) 10) K (// K 4) (// J 4) (* -2 J))) (week (%% h 7))) ; Note that newdep specified dd/mm/yyyy for AC, but mm/dd/-yyyy for BC (while (read-line) (map set '(aa bb year) (map int (parse (current-line) "/"))) (case (sgn year) (0 (println "No zeroth year!")) (+1 (println (zeller aa bb year))) (-1 (println (zeller bb aa (+ year 1)))))) (exit)