How to resolve the algorithm Five weekends step by step in the ERRE programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Five weekends step by step in the ERRE programming language
Table of Contents
Problem Statement
The month of October in 2010 has five Fridays, five Saturdays, and five Sundays.
Algorithm suggestions
Extra credit Count and/or show all of the years which do not have at least one five-weekend month (there should be 29).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Five weekends step by step in the ERRE programming language
Source code in the erre programming language
PROGRAM FIVE_WEEKENDS
DIM M$[12]
PROCEDURE MODULO(X,Y->MD)
IF Y=0 THEN
MD=X
ELSE
MD=X-Y*INT(X/Y)
END IF
END PROCEDURE
PROCEDURE WD(M,D,Y->RES%)
IF M=1 OR M=2 THEN
M+=12
Y-=1
END IF
MODULO(365*Y+INT(Y/4)-INT(Y/100)+INT(Y/400)+D+INT((153*M+8)/5),7->RES)
RES%=RES+1.0
END PROCEDURE
BEGIN
M$[]=("","JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER")
PRINT(CHR$(12);) ! CLS
FOR YEAR=1900 TO 2100 DO
FOREACH MONTH IN (1,3,5,7,8,10,12) DO ! months with 31 days
WD(MONTH,1,YEAR->RES%)
IF RES%=6 THEN ! day #6 is Friday
PRINT(YEAR;": ";M$[MONTH])
CNT%=CNT%+1
! IF CNT% MOD 20=0 THEN GET(K$) END IF ! press a key for next page
END IF
END FOR
END FOR
PRINT("Total =";CNT%)
END PROGRAM
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Forth programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Determinant and permanent step by step in the Python programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the MEL programming language