Passover
March 30, 2010
Here is our calculation of the date of Rosh Hashanah:
(define (rosh-hashanah year)
(let* ((g (+ (remainder year 19) 1))
(r (remainder (* 12 g) 19))
(n (+ (- (quotient year 100) (quotient year 400) 2)
(* 765433 r 1/492480)
(/ (remainder year 4) 4)
(- (/ (+ (* 313 year) 89081) 98496))))
(d (quotient (numerator n) (denominator n)))
(f (- n d))
(j (julian year 9 d)))
(case (modulo j 7)
((2 4 6) (+ j 1))
((0) (if (and (>= f 23269/25920) (> r 11)) (+ j 1) j))
((1) (if (and (>= f 1367/2160) (> r 6)) (+ j 2) j))
(else j))))
In the let
, g is the golden number (the number of the year in the 19-year metonic cycle), n is the calculation given above, d and f are the day and fraction portions of n, respectively, and r and j are temporary variables. The calculation of the date of Passover is simple:
(define (passover year)
(let-values (((y m d) (gregorian (rosh-hashanah year))))
(let ((j (julian year 3 21)))
(if (= m 9) (+ j d) (+ j d 30)))))
For example:
> (gregorian (passover 2010))
2010
3
30
We used julian
and gregorian
from the Standard Prelude. You can run the program at http://programmingpraxis.codepad.org/dPbrwFze.
[…] Praxis – Passover By Remco Niemeijer In today’s Programming Praxis exercise we have to write functions to calculate the dates of the Jewish […]
My Haskell solution (see http://bonsaicode.wordpress.com/2010/03/30/programming-praxis-passover/ for a version with comments):
Python: