Qbasicnews.com
November 17, 2019, 04:23:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3 4 ... 6
  Print  
Author Topic: Easter Sunday computation  (Read 19488 times)
Moneo
Na_th_an
*****
Posts: 1971


« Reply #15 on: June 13, 2003, 02:54:18 PM »

Progger: Thanks for the help re BBCode. I'll try it on my next coding example.
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #16 on: June 13, 2003, 02:58:59 PM »

it also fixes the messed up quoteing
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Mango
Wandering Guru
***
Posts: 360



« Reply #17 on: June 13, 2003, 03:04:52 PM »

Agamemnus,...you can save some typing if you replace this with:

defint a-z

since *all* your variables are intergers...cheers

Code:

CLS
DIM year AS INTEGER, a AS INTEGER, b AS INTEGER, c AS INTEGER
DIM d as integer, e AS INTEGER, f AS INTEGER, g AS INTEGER
DIM h AS INTEGER, i AS INTEGER, j AS INTEGER, k AS INTEGER,
DIM l AS INTEGER, m AS INTEGER, n AS INTEGER, o AS INTEGER
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #18 on: June 13, 2003, 03:37:00 PM »

During my testing of a similar algorithm, I discovereed that ALL the variables dar to be defined as LONG, otherwise it didn't work for large year numbers. So, the original definitions should be changed from INTERGER to LONG. It's like chicken soup --- it wouldn't hurt.
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #19 on: June 13, 2003, 04:18:36 PM »

oh... but then what about really REALLY large years.......  :lol:
Logged

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.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #20 on: June 13, 2003, 08:16:12 PM »

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)
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #21 on: June 13, 2003, 08:21:48 PM »

yeah..
Logged

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.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #22 on: June 14, 2003, 10:47:45 PM »

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.
*****
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #23 on: June 15, 2003, 02:10:19 PM »

Sorry, the code for Easter computation in my previous post is missing the following DECLARE statement up front:

Code:

DECLARE FUNCTION FillString$ (V#,ZL)

*****
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #24 on: June 16, 2003, 05:20:26 AM »

Humm... this may be a silly question, but why did you DEFINT and then make everything LONG?
Logged

Moneo
Na_th_an
*****
Posts: 1971


« Reply #25 on: June 16, 2003, 10:50:23 AM »

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?
*****
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #26 on: June 16, 2003, 06:42:43 PM »

So.. Rio de Janeiro's carnival is how many days before Easter sunday? Cheesy
Logged

Antoni
toonski84
__/--\__
*****
Posts: 2567



« Reply #27 on: June 16, 2003, 06:52:36 PM »

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.
Logged

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
Moneo
Na_th_an
*****
Posts: 1971


« Reply #28 on: June 16, 2003, 08:26:40 PM »

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
*****
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #29 on: June 16, 2003, 08:36:21 PM »

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.
*****
Logged
Pages: 1 [2] 3 4 ... 6
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!