' *** Dooms Day Code Used For Calculating The Day of Week ***
' *** Written by George McGinn
' *** Code shared under Creative Commons License "Universal 1.0 Public Domain (CC0 1.0)"
' *** https://creativecommons.org/publicdomain/zero/1.0/
'
' *** Program will run on Linux, Windows and MAC Systems.
'
'____________________________________________________________________________________________________________________
'
' Doomsday may refer to a hypothetical event according to which the end of human life is at the highest possibility.
' There are many algorithms written to calculate which day of a week in a year has the highest possibility of
' doomsday falling on that day.
'
' This program expands upon and is a generalized version of the Dooms Day Code program, where the formula used in
' combination with the "Special Dates" can easily calculate the Day Of Week (DOW) from a date without any complicated
' algorithms (such as the one that uses the Julian Date from a specific point in time).
'
' See: https://en.wikipedia.org/wiki/Doomsday_rule
'
' SPECIAL DATES
' These are dates that when the Dooms Day Code for the year in question is calculated, these dates all have the
' same DOW.
'
' The "Speical Dates" or "Refernce Dates" where the Doomsday DOW code is the same through the currenly selected
' year are:
' 4/4, 6/6, 8/8, 10/10 and 12/12 --> These set of dates are referred to as "Doubles"
' 5/9, 7/11, 9/5 and 11/7 --> Reverse dates
' 3/14 --> PI Day
' 2/28 or 2/29 --> Non Leap-year (2/28) or Leap-year (2/29)
' 1/3 or 1/4 --> Non Leap-year (1/3) or Leap-year (1/4)
'
' All these days have the same DOW. For example, if it is 9/7/2015, the Doomsday code for 2015 is 06 or "Saturday."
' This means that all the above dates fall on Saturday in 2015 (use the non Leap-year dates).
'
' To use this to find out what day-of-week 9/7/2015 falls on, find the closest day from the reference dates, and
' do a simple addition or subtraction. The date 9/7 is the closest date, and we know that 9/7 is a "Saturday" based
' on the calculated Doomsday code. We only need to subtract 5 from 7, giving us 2, then subracting 2 from 6, giving
' us 4. DOW(4) = Thurdsday. So 9/7/2015 falls on a Thursday.
'
' If we want to calculate the DOW that Christmas falls on in 2015 (12/25/2015) the same proceedure is used.
' The closest reference date is 12/12. Subtracting 12 from 25 gives us 13. 13 MOD 7 = 6. Since 6 is one day short
' of a whole week, we only need to subtract one day from the Doomsday Code ((7-6)-1)=5. Christmas 2015 is on Friday.
'
' This program uses this logic to calculate any DOW from any date from 1583 to well into the future. Any date before
' the Gregorian Calendar was adopted in your country will give you inaccurate results. Check the following link:
' https://en.wikipedia.org/wiki/List_of_adoption_dates_of_the_Gregorian_calendar_per_country
'
'
' PROGRAM NOTES
'
' This program uses both the Dooms Day algorithm and incorporates the mental math trick to calculate the Day-of-Week
' in your head. By using this method makes the code (and process of) more understandable and slightly faster than
' using the complex algorithms using the Julian Date and doing all the divisions by 4, 100 and 400 for Leap Years.
'
' Below is a description of what each FUNCTION/SUBROUTINE does in this program:
'
' floor - A C++ Library that does not round up numbers when converting FLOAT to INTEGER. (Thanks to
' both Fleppie and Spriggs for this)
'
' dooms_day_code - Calculates the Doomsday Code for the century of the supplied date. This is needed as input into
' the calculation of the actual year's Dooms Date code.
'
' dooms_date - Takes the century "anchor" code from dooms_day_code and calculates the Dooms Day code for the
' actual year of the date. This will be used to calculate the Day-of-Week for the date supplied.
'____________________________________________________________________________________________________________________
'*** map to store days value of anchor day can be known
dict_day$(0) = "Sunday"
dict_day$(1) = "Monday"
dict_day$(2) = "Tuesday"
dict_day$(3) = "Wednesday"
dict_day$(4) = "Thursday"
dict_day$(5) = "Friday"
dict_day$(6) = "Saturday"
main:
'*** Enter Year for Dooms Day Code and Display results
INPUT "Enter YEAR (CCYY): "; year
PRINT "*** ERROR: Date Invalid/Out Of Range"
'*** Get the Doomsday Code for the anchor
dow_anchor = dooms_day_code(year)
'*** Get the Doomsday Code using the century anchor for the year's actual Doomsday code and display
PRINT "Doomsday in the year "; year;
" = "; dict_day$
(dooms_day
(year
, dow_anchor
))
'
' *** End of Main
'____________________________________________________________________________________________________________________
'*** FUNCTIONS AND SUBROUTINES
'
DIM yr$
, cc_str$
, yy_str$
'*** Split out the century from the year and create two variables
'*** Dooms day formula by1 John Conway
dooms_day
= (yy
+ floor
(yy
/ 4) + anchor
) MOD 7
DIM yr$
, cc_str$
, yy_str$
'*** Split out the century from the year and create two variables
'*** Decide the anchor day
anchor = 0
anchor = 5
anchor = 3
anchor = 2
anchor = 0
anchor = 5
'*** Dooms day formula by John Conway
dooms_day_code
= ((floor
(y
/ 12) + y
MOD 12 + floor
(y
MOD 12) / 4) MOD 7 + anchor
) MOD 7
'
' *** End of Program Source
'____________________________________________________________________________________________________________________