Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Easter Sunday computation
#21
The algorithm that I have by Knuth states that it will work up to the year 99999. When I implemented it, I considered that a max of year 9999 would be enough, especially since most date handling programs only handle 4 digit years.

Even though a max of 9999 fits into an integer, I had problems with the arithmetic of the algorithm when testing with larger numbers. I can't remember whether "large" meant over 6000 or over 8000. I just used LONG and the problem went away.

Let's not forget what I mentioned about MOD not working for negative numbers. There are instances when the arithmetic produces an intermediate result that's negative.
For example, if you intend to do the following on the intermediate value called ZZZ:

RESULT = ZZZ MOD 30

If you think ZZZ could be negative, then I sugest taking the MOD as follows:

RESULT = ZZZ-30*INT(ZZZ/30)
Reply
#22
yeah..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#23
Although there was only one person, Antoni, who wanted to see the code, I'm going to list it here to relieve you guys from having to debug your other versions.

Code:
REM **************************************************************************
REM ***** COMPUTATION OF EASTER **********************************************
REM **************************************************************************

DEFINT A-Z

DECLARE FUNCTION Easter$     (YYYY)

DIM YYYY AS INTEGER  'Value of the given 4 digit year.

***** your program code here to get YYYY *****

'* Compute date of Easter Sunday for the year YYYY.

EasterSunday$ = EASTER(YYYY)

***** your program code here to display EasterSunday$ *****

REM **************************************************************************

END

REM **************************************************************************
REM *****   F U N C T I O N S   **********************************************
REM **************************************************************************

' ======================= EASTER ============================================
' Computes date of Easter Sunday for input year.
' Acknowledgement and thanks to Donald E. Knuth.
' Ref: The Art of Computer Programming, Volume 1 Fundamental Algorithms, 1.3.2.
' Knuth's algorithm was implemented as such, with no enhancements.
' According to Knuth, this logic will work up to a 5 digit year.
' This logic has been tested up to the year 9999.
' The resultant Easter dates have been verified for years 1901 through 2100.
' ===========================================================================

FUNCTION Easter$ (YYYY) STATIC

REM *
REM *** COMPUTE DATE OF EASTER SUNDAY FOR GIVEN YEAR.
REM *
REM *  INPUT: YYYY assumed to be a 4 digit year (max 9999)
REM *
REM * OUTPUT: a date string formatted as YYYYMMDD.
REM *
REM *  USAGE: E$ = EASTER$(YYYY)

'* All variables are set to LONG to handle arithmetic
'* for large year numbers.

DIM Y    AS LONG  
DIM G    AS LONG
DIM C    AS LONG
DIM X    AS LONG
DIM Z    AS LONG
DIM D    AS LONG
DIM E    AS LONG
DIM TEMP AS LONG
DIM N    AS LONG


Y = YYYY   '* Force year as long

           '* Compute "golden number" of the year in the 19-year Metonic cycle.
G = (Y mod 19) + 1
           '* Compute the Century. Note: When Y is not multiple of 100,
           '*                            C is the century number.
C = INT(Y/100) + 1
           '* Corrections:
           '* X is number of years, like 1900, in which leap year was dropped
           '*                       in order to keep in step with the sun.
           '* Z is special correction to sync Easter with the moon's orbit.
X = INT(3*C/4) - 12
Z = INT((8*C + 5) / 25) - 5
           '* Find Sunday
D = INT(5*Y/4) - X - 10
           '* Compute so-called Epact, which specifies when a full moon occurs.
TEMP = (11*G + 20 + Z - X)
E    = TEMP-30*INT(TEMP/30)   'Same as TEMP MOD 30 but works for negative TEMP.
if (E=25 and G>11) or E=24 then E=E+1
           '* Find full moon. Easter is the 1st Sunday after the 1st full moon
           '*                 which occurs on or after March 21st.
           '*                 This is a "calendar moon" not actual moon.
N = 44 - E
if N<21 then N=N+30
           '* Advance to Sunday.
N = N + 7 - ( (D+N) mod 7 )
           '* Get Month.
           '* N is the day.
if N>31 then
   zmm=4              'April
   N=N-31
else
   zmm=3              'March
end if
          '* Pack Easter date as YYYYMMDD
Easter$=FILLSTRING$((Y),4)+FILLSTRING$((zmm),2)+FILLSTRING$((N),2)

END FUNCTION
' ============================================================================

' ========================= FILLSTRING =============================
' Converts a value to string of specified length with leading zeros.
' ==================================================================
FUNCTION FillString$ (V#,ZL) STATIC

  FILLSTRING$=right$(STRING$(ZL,"0")+MID$(STR$(V#),2),ZL)
END FUNCTION
' ===================================================================
Note: This Easter function has been working for years. If it gives you any trouble at all, let me know.
*****
Reply
#24
Sorry, the code for Easter computation in my previous post is missing the following DECLARE statement up front:

Code:
DECLARE FUNCTION FillString$ (V#,ZL)
*****
Reply
#25
Humm... this may be a silly question, but why did you DEFINT and then make everything LONG?
Reply
#26
Mostly force of habit, plus the fact that I do have some code of my own where it says "put your own code here..."
Have you tried the routine yet?
*****
Reply
#27
So.. Rio de Janeiro's carnival is how many days before Easter sunday? Big Grin
Antoni
Reply
#28
by that smiley, i take it you're kidding, but for those who dont know, Ash Wednesday marks the first day of Lent, which in Catholicism is a period of the 40 days before Easter, skipping Sundays.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#29
Lent begins on Ash Wednesday for 40 days and ends on Palm Sunday.
Rio's carnival begins on the weekend before Ash Wednesday, and ends the day before Ash Wednesday known in Spanish as martes de carnaval (carnival Tuesday).

So working backwards from Easter........................ 20-Apr-2003
Palm Sunday is the previous Sunday..................... 13-Apr-2003
Ash Wednesday is 39 days before Palm Sunday... 05-Mar-2003
*****
Reply
#30
I wonder where you got the formula about Lent being 40 days before Easter skipping Sundays.
That just doesn't work.

In addition, Holy Week, the week immediately before Easter Sunday, is not part of Lent. Lent ends on Palm Sunday. Lot's of people do confuse this.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)