Entry
BBCBASIC: Windows: Date: How to calculate in your head week day of given date? [Doomsday algorithm]
Mar 11th, 2007 11:50
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 11 March 2021 - 08:12 pm ----------------------
BBCBASIC: Windows: Date: How to calculate in your head
week day of given date? [Doomsday algorithm]
---
--- cut here: begin --------------------------------------------------
PRINT "Calculating the day of the week yourself in your head"
PRINT
PRINT "using the Doomsday algorithm"
PRINT
PRINT "http://en.wikipedia.org/wiki/Doomsday_algorithm"
PRINT
PRINT "This algorithm was invented by John Conway"
PRINT
PRINT "http://en.wikipedia.org/wiki/John_Horton_Conway"
PRINT
PRINT "Now determining the day of the week, from your given date"
PRINT
INPUT "0.1 What is the day (e.g. 11) = "; dayI%
PRINT
INPUT "0.2 What is the month (e.g. 3) = "; monthI%
PRINT
INPUT "0.3 What is the year (e.g. 2007) = "; yearI%
PRINT
INPUT "0.4 What are the last two digits of the year (e.g. if 2007,
take 07, or thus 7) = " yearLastTwoDigitsI%
IF yearLastTwoDigitsI% <> ( yearI% MOD 100 ) THEN PRINT "wrong, the
correct answer is "; ( yearI% MOD 100 ); " please try again" : STOP
PRINT
INPUT "1. Divide the year's last two digits by 12, and take the
integral value of the quotient = " aI% : REM a
IF aI% <> ( yearLastTwoDigitsI% DIV 12 ) THEN PRINT "wrong, the
correct answer is "; ( yearLastTwoDigitsI% DIV 12 ); " please try
again" : STOP
PRINT
INPUT "2. Take the remainder of the same quotient = " bI% : REM b
IF bI% <> ( yearLastTwoDigitsI% MOD 12 ) THEN PRINT "wrong, the
correct answer is "; ( yearLastTwoDigitsI% MOD 12 ); " please try
again" : STOP
PRINT
INPUT "3. Divide that remainder by 4 and take the integral value = "
cI% : REM c
IF cI% <> ( bI% DIV 4 ) THEN PRINT "wrong, try again" : STOP
PRINT
INPUT "4. Determine the sum of this 3 numbers a, b and c (possible
divide by this sum by 7 and take the integral value of this quotient)
(=d) = " dI%
IF NOT ( dI% = ( aI% + bI% + cI% ) OR dI% = ( aI% + bI% + cI% ) MOD
7 ) THEN PRINT "wrong, the correct answer is "; ( aI% + bI% +
cI% ); "or otherwise "; ( aI% + bI% + cI% ) MOD 7; ". Please try
again" : STOP
PRINT
PRINT "5. Count forward the specified number of days from the fixed
anchor day for your century, to get that year's Doomsday"
INPUT "5.1 What is the anchor day for that century (choose from
Monday/Tuesday/Wednesday/Thursday/Friday/Saturday/Sunday) = ";
yourAnchorDay$
anchorDay$ = FNStringGetDateDoomsdayS( yearI% )
IF ( yourAnchorDay$ <> anchorDay$ ) THEN PRINT "wrong, the correct
answer is "; anchorDay$; ". Please try again" : STOP
INPUT "5.2 What is the day (=Doomsday) after you counted forward
(choose from Saturday/Sunday/Monday/Tuesday/Wednesday/Thursday/Friday)
= "; yourDoomsDay$
doomsDay$ = FNMathGetDateIntegerToDayS( ( FNStringGetDateDayToIntegerI
( anchorDay$ ) + dI% ) MOD 7 )
IF ( yourDoomsDay$ <> doomsDay$ ) THEN PRINT "wrong, the correct
answer is "; doomsDay$; ". Please try again" : STOP
PRINT
PRINT "Now you know that the 'even' dates 4/4, 6/6, 8/8, 10/10, 12/12"
PRINT "(and further the 'odd' dates 5/9, 9/5, 7/11, 11/7" : REM
mnemonic "I work from 9 to 5 at the 7-11"
PRINT "and 0/3 (that is the day before the 1st of March)"
PRINT "all also fall on this doomsday."
PRINT "Now you just calculated which weekday this is (=";
doomsDay$; ")."
PRINT "Now calculate backward or forward from this known 4/4, 6/6 ...
weekdays to the day you want to know in that month."
PRINT "e.g. if you know that 4/4 is Tuesday, then you know 5/4 is a
Wednesday, 6/4 is a Thursday, ... and so on."
PRINT " and further you know that this pattern repeats itself
every 7 days again. Thus e.g. 11/4 is a Tuesday, 18/4 is a
Tuesday, ... and so on."
PRINT
INPUT "Thus what is the day of week of your given calendar date
(choose from Saturday/Sunday/Monday/Tuesday/Wednesday/Thursday/Friday)
= " yourWeekDay$
weekDay$ = FNMathGetDateIntegerToDayS( FNDate_DayOfWeek( dayI%,
monthI%, yearI% ) )
PRINT
IF weekDay$ = yourWeekDay$ THEN
PRINT "Your answer is correct!"
ELSE
PRINT "wrong, the correct answer is "; weekDay$; ". Please try
again" : STOP
ENDIF
END
:
:
:
DEF FNStringGetDateDoomsdayS( yearI% )
IF ( 1800 <= yearI% ) AND ( yearI% <= 1899 ) THEN = "Friday"
IF ( 1900 <= yearI% ) AND ( yearI% <= 1999 ) THEN = "Wednesday" : REM
mnenomic "We-in-dis-day (most of us where born in that century)"
IF ( 2000 <= yearI% ) AND ( yearI% <= 2099 ) THEN = "Tuesday" : REM
mnenomic "Y-Tue-K, Y2K was the head of this century"
IF ( 2100 <= yearI% ) AND ( yearI% <= 2199 ) THEN = "Sunday"
PRINT "please choose your year between 1800 and 2199 (but you can
amend this program to take in account a larger date range, as Doomsday
repeats itself every 400 years)" : STOP
:
DEF FNStringGetDateDayToIntegerI( s$ )
LOCAL dayI%
CASE s$ OF
WHEN "Sunday"
dayI% = 1
WHEN "Monday"
dayI% = 2
WHEN "Tuesday"
dayI% = 3
WHEN "Wednesday"
dayI% = 4
WHEN "Thursday"
dayI% = 5
WHEN "Friday"
dayI% = 6
WHEN "Saturday"
dayI% = 7
OTHERWISE
PRINT; "unknown day (please choose from
Saturday/Sunday/Monday/Tuesday/Wednesday/Thursday/Friday)"; s$ : STOP
ENDCASE
= dayI%
:
DEF FNMathGetDateIntegerToDayS( dayI% )
LOCAL s$
CASE dayI% OF
WHEN 1
s$ = "Sunday"
WHEN 2
s$ = "Monday"
WHEN 3
s$ = "Tuesday"
WHEN 4
s$ = "Wednesday"
WHEN 5
s$ = "Thursday"
WHEN 6
s$ = "Friday"
WHEN 7
s$ = "Saturday"
OTHERWISE
PRINT; "unknown day number "; dayI%; ". Please choose an integer
number between 1 and 7)" : STOP
ENDCASE
= s$
:
REM library - FNDate_DayOfWeek(day%,month%,year%) - return day of
week for supplied date - 1=Sunday, 7=Saturday - author: J. G. Harston -
http://www.mdfs.net/System/Library/BLib/
DEF FNDate_DayOfWeek( d%, m%, y% )
y% = y% MOD 400
= ( y% * 365.25 + m% * 30 + d% + VAL MID$( "120112234455", m%, 1 ) +
( ( y% MOD 4 ) = 0 ) - ( (y% - 1 ) DIV 100 ) - (m% > 2 AND ( ( y% MOD
4 )= 0 AND( y% MOD 100 ) <> 0 OR y% = 0 ) ) + 3 ) MOD 7 + 1
:
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
Doomsday algorithm
http://en.wikipedia.org/wiki/Doomsday_algorithm
---
John Conway
http://en.wikipedia.org/wiki/John_Horton_Conway
---
Daniel Tammet
http://en.wikipedia.org/wiki/Daniel_Tammet
---
Daniel Tammet calculating the day of the week video
http://60minutes.yahoo.com/segment/44/brain_man
----------------------------------------------------------------------