Qbasicnews.com
November 17, 2019, 04:44:47 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 ... 6
  Print  
Author Topic: Easter Sunday computation  (Read 19489 times)
Moneo
Na_th_an
*****
Posts: 1971


« on: June 12, 2003, 07:01:47 PM »

Is anyone interested in appproximately 30 lines of straight-line code (plus comments) to compute the date (YYYYMMDD) of  Easter Sunday in any given year?
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: June 12, 2003, 07:34:23 PM »

However I don't have any idea which Sunday of which month Easter is on.......
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.
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #2 on: June 12, 2003, 07:40:56 PM »

Is this for homework? Or have you done it? Though it would fit in well.

http://www.hourworld.com/easter.htm Gregorian or Julian?
Logged

Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #3 on: June 12, 2003, 08:14:29 PM »

So much fuss to calculate the date of the first sunday after the first full moon after the spring equinox?Huh  Cheesy

Well, if you think about it, it must be a very serious algorithm.  So congratulations! Shocked

And yes, I would be interested in seeing the code.  :bounce:
Logged

Antoni
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #4 on: June 12, 2003, 08:36:28 PM »

cool beans....

I just made mine...

It's 23 lines (with dims, cls, print, and input)
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 #5 on: June 12, 2003, 09:16:08 PM »

Quote from: "Agamemnus"
However I don't have any idea which Sunday of which month Easter is on.......


Easter Sunday is a moveable feast which falls in March or April. By definition, except for Orthodox churches, it is the first Sunday after the date of the first full moon that occurs on or after March 21st.

The programming problem is computing when this first full moon occurs. Why would you need this?
1) Let's say you're planning to go on a trip to Rio de Janeiro for the carnival festival in 2006 and you can't find a calendar for 2006.
Carnival in Rio begins on the weekend before Ash Wednesday. If you know when Easter falls that year, you can figure out easily when Ash Wednesday falls.
2) Let's say you're programming a payroll and are given a list of company holidays which includes Good Friday. If the program can't figure out when Easter is, then it can't figure Good Friday. Without the Easter logic, every year someone would have to remember to set the date for the Good Friday holiday.
3) I'm certain there are many other uses.

So, back to my original question: Are you interested in the routine? Yes or no.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #6 on: June 12, 2003, 09:35:37 PM »

Quote from: "oracle"
Is this for homework? Or have you done it? Though it would fit in well.

http://www.hourworld.com/easter.htm Gregorian or Julian?

**************************************************
The mentioned website has the specifications for a computation of Easter taken from Butcher's Ecclesiastical Calandar of 1876. It might be good, but I wouldn´t like to spend the time debugging the programmed interpretation of these ancient specifications.

The specifications that I used were written by Donald E. Knuth in his renowned series of books called "The Art of Programming", specifically from the book "Fundamental Algorithms". Look him up. His algorithm were designed to be programmed.

Are you interested in the code for this version? Yes or no?
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #7 on: June 12, 2003, 09:40:44 PM »

I've been exchanging emails with Moneo for a few days. This guy is a QB genius. :wink:
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #8 on: June 12, 2003, 09:44:07 PM »

what I saw on the website weren't specifications but ALMOST code.

Had to replace x with * and set all vars to integers..

2003 = 4, 20.

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

INPUT year

a = year MOD 19
b = year \ 100
c = year MOD 100
d = b \ 4
e = b MOD 4
f = (b + 8) \ 25
g = (b - f + 1) \ 3
h = ((19 * a) + b - d - g + 15) MOD 30
i = c \ 4
j = c MOD 4
k = (32 + 2 * e + 2 * i - h - j) MOD 7
l = (a + 11 * h + 22 * k) \ 451
m = (h + k + 7 * l + 114)
n = m \ 31
o = m MOD 31 + 1
PRINT n; o


Hmmmmmmmmm...... "Mexico QB Central" or "QB Mexico Central"
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.
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #9 on: June 12, 2003, 10:03:52 PM »

Code:
CLS
INPUT year
a = year MOD 19
b = INT(year / 100)
c = year MOD 100
d = INT(b / 4)
e = b MOD 4
f = INT((b + 8) / 25)
g = INT((b - f + 1) / 3)
h = ((19 * a) + b - d - g + 15) MOD 30
i = INT(c / 4)
j = c MOD 4
k = (32 + (2 * e) + (2 * i) - h - j) MOD 7
l = INT((a + (11 * h) + (22 * k)) / 451)
m = INT((h + k - (7 * l) + 114) / 31)
n = 1 + ((h + k - (7 * l) + 114) MOD 31)
PRINT USING "####:##:##"; year; m; n


All i did was this.
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Moneo
Na_th_an
*****
Posts: 1971


« Reply #10 on: June 12, 2003, 10:50:01 PM »

Quote from: "Agamemnus"
what I saw on the website weren't specifications but ALMOST code.

Had to replace x with * and set all vars to integers..

2003 = 4, 20.

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

INPUT year

a = year MOD 19
b = year \ 100
c = year MOD 100
d = b \ 4
e = b MOD 4
f = (b + 8) \ 25
g = (b - f + 1) \ 3
h = ((19 * a) + b - d - g + 15) MOD 30
i = c \ 4
j = c MOD 4
k = (32 + 2 * e + 2 * i - h - j) MOD 7
l = (a + 11 * h + 22 * k) \ 451
m = (h + k + 7 * l + 114)
n = m \ 31
o = m MOD 31 + 1
PRINT n; o


Hmmmmmmmmm...... "Mexico QB Central" or "QB Mexico Central"

**************************************************
Ok, you now have some virgin code for an intricate problem. Get youself a copy of The Farmer's Almanac, which has a long list of dates for Easter Sunday, and check out about 50 random years, going back about 200 years and forward for about 200 years. Make sure to select a good number of leap years. When you've done this, and the dates check out exactly, you can consider that the routine works in general. When you get to this point, let me have a crack at testing it.
P.S. While testing my version, I discovered that the MOD instruction in QB does not work on negative number. I had to do this  function the long way.
Have fun!
P.S. This "QB Central" guy now lives in Mexico City but was born and learned how to program in New York, New York.
*****************************************************
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #11 on: June 13, 2003, 03:14:00 AM »

Mr moneo, you may find turning BBCode on a good idea, because your posts, no matter how insightful, look frighteningly ugly.

Quote from: "moneo"
P.S. This "QB Central" guy now lives in Mexico City but was born and learned how to program in New York, New York.


Only an american could write new york twice like the rest of the world was ignorant  Tongue
Logged

Agamemnus
x/ \z
*****
Posts: 3491



« Reply #12 on: June 13, 2003, 09:28:52 AM »

There is Buffalo, New York, too......

Well, the website seems like it's good..

Anyways, you put [/quote] instead of [/code]......
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 #13 on: June 13, 2003, 02:33:08 PM »

Quote from: "oracle"
Mr moneo, you may find turning BBCode on a good idea, because your posts, no matter how insightful, look frighteningly ugly.

Quote from: "moneo"
P.S. This "QB Central" guy now lives in Mexico City but was born and learned how to program in New York, New York.


Only an american could write new york twice like the rest of the world was ignorant  Tongue

**************************************************
Oracle, Thanks for your personal comments:
1) I joined this forum only yesterday and don't know what BBCode is, nor where to read about it --- please advise.
2) I said New York, New York to indicate New York City, specifically Manhattan, just like the song "New York New York". Ok?
**************************************************
Logged
pr0gger
I hold this place together
*****
Posts: 775


« Reply #14 on: June 13, 2003, 02:38:36 PM »

Moneo-- BBCode is the code used to format text in this forum.  They're the little tags like [url],
Quote
, etc.

To enable it when you post, look at the first checkbox right under the textbox where you enter text.  If there's a check in it, uncheck it.

More about BBCode:

http://forum.qbasicnews.com/faq.php?mode=bbcode
Logged

size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Pages: [1] 2 3 ... 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!