' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.10.01.33]) on 2024.10.08 at 22:12 (Coordinated Universal Time)
_TITLE "Weekday Program"
' Originally a BAM port by Charlie Veniot of a program shared by Carlos Mencia
' However, that algorithm was incorrect, as discovered by TDarcos:
' - entering January 1, 1800 ought to give Wednesday and Mencia's algorithm was giving Tuesday !
'
' I've replaced Mencia's algorithm with code matching the BASIC code for the "Doomsday Rule" task at Rosettacode
' (https://rosettacode.org/wiki/Doomsday_rule#BASIC)

🟡🟡🟡_Declarations:

    CONST Weekday$(1 TO 7) = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
    SUB PrintItem(label$,v$)
        COLOR 14 : PRINT LEFT$(label$ + ":" + SPACE$(5), 9); : COLOR 15 : PRINT v$
    END SUB

    ' The following are ported/modded from the referenced line numbers of the BASIC program at Rosettacode
    🔆020: DIM Da( 12, 1 ): FOR I = 0 TO 1 : FOR J = 1 TO 12 : READ Da(J,I): NEXT J,I
    🔆120: DATA 3,7,7,4,2,6,4,1,5,3,7,5
    🔆130: DATA 4,1,7,4,2,6,4,1,5,3,7,5
    
🟡🟡🟡_MainProgram:

    005 SCREEN _NEWIMAGE(144, 112, 7)

    010 CLS : SLEEP 0.01
    011 inD = PROMPT( " WHICH WEEKDAY ?\n\n DAY:", MID$( DATE$, 4, 2) )
        inM = PROMPT( " WHICH WEEKDAY ?\n\n DAY: " + inD + "\n MONTH: " , MID$( DATE$, 1, 2) )
        inY = PROMPT( " WHICH WEEKDAY ?\n\n DAY: " + inD + "\n MONTH: " + inM + "\n YEAR: " , MID$( DATE$, 7, 4) )

    ' The following are ported/modded from the referenced line numbers of the BASIC program at Rosettacode
    🔆050: C = inY \ 100 : R = inY MOD 100
    🔆060: S = R \ 12 : T = R MOD 12
    🔆070: A = ( 5 * ( C AND 3 ) + 2 ) MOD 7
    🔆080: B = ( S + T + ( T \ 4 ) + A ) MOD 7
    🔆090: DAY = ( B + inD - Da( inM, -( inY MOD 4 = 0 AND ( inY MOD 100 <> 0 OR inY MOD 400 = 0 ))) + 7 ) MOD 7 + 1

    100 COLOR 11 : PRINT "WHICH WEEKDAY ?" : PRINT
        PrintItem( "DAY", inD )
        PrintItem( "MONTH", inM )
        PrintItem( "YEAR", inY )
    110 PRINT : PrintItem( "WEEKDAY", Weekday$(DAY) )
    
    130 COLOR 7 : PRINT
        PRINT "Click/touch the
        PRINT "screen or press"
        PRINT "a key on your"
        PRINT "keyboard to find"
        PRINT "another weekday."
        SLEEP
        GOTO 10
    
    140 END


' 🟡🟡🟡 Original program by Carlos Mencia
'        The program mishandles January 1, 1800 (giving Tuesday instead of the correct Wednesday)

    '10 PRINT " WHICH WEEKDAY ?"
    '20 CLEAR:INPUT "Day:";D:INPUT "Month:";M:INPUT "Year:";Y
    '30 I=INT(Y/100):Y=Y-I*100:IF M<3 THEN LET M=M+12:Y=Y-1
    '40 Z=(D+INT(2.6*(M+1))+INT(1.25*Y)+INT (I/4)-2*I-1)
    '50 X=Z/7:Y=Z-INT(X)*7
    '60 IF Y=0 THEN PRINT "Sunday"
    '70 IF Y=1 THEN PRINT "Monday"
    '80 IF Y=2 THEN PRINT "Tuesday"
    '90 IF Y=3 THEN PRINT "Wednesday"
    '100 IF Y=4 THEN PRINT "Thursday"
    '110 IF Y=5 THEN PRINT "Friday"
    '120 IF Y=6 THEN PRINT "Saturday"
    '130 PRINT :INPUT"Again Y/N";Q$:IF Q$="Y"THEN 20
    '140 END