Passover

March 30, 2010

The Jewish holiday of Passover celebrates the biblical event when, during the Jewish captivity in Egypt, God killed the first-born child of every person and cattle in Egypt, except in those homes whose doorposts were marked with the blood of a spring lamb, which were passed over; as a result, the Jewish people were able to escape enslavement in Egypt.

Passover is celebrated on the date of the first full moon after the spring equinox, with some adjustments. British mathematician John Horton Conway gives this algorithm for calculating the date of Passover:

First, calculate the date of Rosh Hashanah, the Jewish new year. In gregorian year y of the common era, Rosh Hashanah falls on September n, where:

g = remainder(y/19) + 1

n + fraction =
  ( floor(y/100) - floor(y/400) - 2)
  + 765433/492480 × remainder(12g/19)
  + remainder(y/4) / 4
  - (313y + 89081) / 98496

The calculation of n is subject to the following postponement rules:

  1. If the day calculated above is a Sunday, Wednesday, or Friday, Rosh Hashanah falls on the next day (i.e., Monday, Thursday or Saturday, respectively).
  2. If the day calculated above is a Monday, and if the fraction is greater than or equal to 23269/25920, and if remainder(12g/19) is greater than 11, Rosh Hashanah falls on the next day, a Tuesday.
  3. If the day calculated above is a Tuesday, and if the fraction is greater than or equal to 1367/2160, and if remainder(12g/19) is greater than 11, Rosh Hashanah falls two days later, on Thursday.

Given the date of Rosh Hashanah, the date of Passover in the same calendar year is calculated as m days after March 21, where m is the day of September on which Rosh Hashanah falls, if Rosh Hashanah is in September, or thirty plus the day of October on which Rosh Hashanah falls, if Rosh Hashanah is in October.

According to Jewish custom, the holiday actually begins at sunset on the day prior to that calculated above.

Your task is to write functions that calculate the dates of Rosh Hashanah and Passover for any given calendar year. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

About these ads

Pages: 1 2

3 Responses to “Passover”

  1. […] Praxis – Passover By Remco Niemeijer In today’s Programming Praxis exercise we have to write functions to calculate the dates of the Jewish […]

  2. Remco Niemeijer said

    My Haskell solution (see http://bonsaicode.wordpress.com/2010/03/30/programming-praxis-passover/ for a version with comments):

    import Data.Time.Calendar
    import Data.Time.Calendar.WeekDate
    import Data.Fixed
    
    roshDay :: Integer -> Integer
    roshDay year | elem d [3,5,7] = n + 1
                 | d == 1 && f >= 23269/25920 && r > 11 = n + 1
                 | d == 2 && f >= 1367/2160   && r > 6 = n + 2
                 | otherwise = n
        where
        y = fromIntegral year
        g = mod' y 19 + 1
        r = mod' (12 * g) 19
        a // b = fromIntegral $ floor (a / b)
        (n, f) = properFraction (y // 100 - y // 400 - 2 +
                                 765433/492480 * r + mod' y 4 / 4 -
                                 (313 * y + 89081) / 98496)
        (_,_,d) = toWeekDate . addDays n $ fromGregorian year 8 31
    
    roshHashanah :: Integer -> Day
    roshHashanah year = addDays (roshDay year) (fromGregorian year 8 31)
    
    passover :: Integer -> Day
    passover year = addDays (roshDay year) (fromGregorian year 3 21)
    
  3. Mike said

    Python:

    from math import floor
    from datetime import date, timedelta
    
    def rosh_hashanah(year):
        g = year % 19 + 1
        r = 12*g % 19
    
        v =  ( floor( year / 100.0 ) - floor( year / 400.0 ) - 2 )
        v += 765433.0 * r / 492480
        v += ( year % 4 ) / 4.0
        v -= ( 313.0 * year + 89081 ) / 98496
    
        n = int(v)
        f = v - n
    
        # Monday .. Sunday = 0..6
        dow = ( date( year, 8, 31 ).weekday() + n ) % 7
    
        if dow in (2,4,6):
            n += 1
        elif dow == 0 and f >= 23269.0 / 25920 and r > 11:
            n += 1
        elif dow == 1 and f >= 1367.0 / 2160 and r > 6:
            n += 2
    
        return n
    
    def passover(year):
        return date(year,3,21) + timedelta(rosh_hashanah(year))
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 635 other followers

%d bloggers like this: