Welcome, Guest. Please login or register.

Author Topic: Easter Day calculations  (Read 1688 times)

Offline Egil

  • Member
  • **
  • Posts: 83
    • View Profile
Easter Day calculations
« on: August 30, 2014, 07:48:20 AM »
Console programs make things easy if you want to test out an idea or two for use in your own programs. When finished, the code can be used in ordinary Windows programs, as long as it does not affect the GUI. I use this method all the time, and this example is no exception.
First, a little background: I am a great fan of the cult book "Hitchhiker's Guide to the Galaxy", and if I ever see a reference to it when browsing the internet, I check it out. This is one such example.
The BBC have made several radio theater episodes of the book, and still use it for educational purposes in their childrens radio programming section. This example started when I checked out this link: http://www.bbc.co.uk/dna/h2g2/A653267
When I read that article I just HAD to try....  ( that site is full of other programming ideas as well, just see for yourself).

Here we go:

Code: [Select]
'
' Easter.cba
'
DECLARE Easter(y:int)
def year:int

openconsole
input"Enter year: ",year
print
print Easter(year)

do:until inkey$<>""
closeconsole
end
'*************************** END OF TEST ROUTINE *******************************

'
SUB Easter(Year:int)
'-------------------------------------------------------------------------------
' Calculate date of Easter Day - (valid from 1700 to 2299)
' Algorithm from:  http://www.bbc.co.uk/dna/h2g2/A653267
' Input:  Year as integer
' Return: Date as formatted string ("yyyy-MM-dd")
'     or: Date as ISO formatted string ("yyyyMMdd")
'-------------------------------------------------------------------------------
def a,b,c,d,e,f,g,h,i,j,k,m,n,Month,Day:int

a = Year % 19
b = int(Year/100)
c = Year % 100
d = int(b/4)
e = b % 4
f = int(c/4)
g = c % 4
h = int((b+8)/25)
i = int((b-h+1)/3)
j = ((19*a) + b - d - i + 15) % 30
k = (32 + (2*e) + (2*f) - j - g) % 7
m = int((a+(11*j)+(22*k))/451)
n = j + k - (7*m) + 114
Month = int(n/31)
Day = (n%31) + 1

'  Use one of the two alternatives below - or modify to suit your needs

' Return date as string:
RETURN using("0####", Year) + "-" + using("0##", Month) + "-" + using("0##", Day)+"   (Year-Month-Day)"

' Return date as ISO formatted string:
'RETURN using("0####", Year) + using("0##", Month) + using("0##", Day)


Have fun!

Egil

Support amateur radio  -  have a ham for dinner...