Five weekends: Difference between revisions

Content added Content deleted
(Added Dart example)
(Added solution for Action!)
Line 151: Line 151:
201 occurrences
201 occurrences
29 years with no five weekend month
29 years with no five weekend month
</pre>

=={{header|Action!}}==
Day of the week is determined using [https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods Sakamoto] method.
<lang Action!>;https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods
BYTE FUNC DayOfWeek(INT y BYTE m,d) ;1<=m<=12, y>1752
BYTE ARRAY t=[0 3 2 5 0 3 5 1 4 6 2 4]
BYTE res

IF m<3 THEN
y==-1
FI
res=(y+y/4-y/100+y/400+t(m-1)+d) MOD 7
RETURN (res)

PROC Main()
BYTE ARRAY m31=[1 3 5 7 8 10 12]
INT ARRAY years(250)
BYTE ARRAY months(250)
INT y
BYTE i,m,mCount,yCount,found,c

mCount=0 yCount=0 c=0
FOR y=1900 TO 2100
DO
found=0
FOR i=0 TO 6
DO
m=m31(i)
IF DayOfWeek(y,m,1)=5 THEN
years(mCount)=y
months(mCount)=m
found=1
mCount==+1
FI
OD
IF found=0 THEN
yCount==+1
FI
OD
Print("5-weekend months in 1900-2100: ") PrintBE(mCount)
Print("non 5-weekend years in 1900-2100: ") PrintBE(yCount)
PutE()

FOR i=0 TO 4
DO
PrintI(years(i)) Put('/) PrintBE(months(i))
OD
PrintE("...")
FOR i=mCount-5 TO mCount-1
DO
PrintI(years(i)) Put('/) PrintBE(months(i))
OD
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Five_weekends.png Screenshot from Atari 8-bit computer]
<pre>
5-weekend months in 1900-2100: 201
non 5-weekend years in 1900-2100: 29

1901/3
1902/8
1903/5
1904/1
1904/7
...
2097/3
2098/8
2099/5
2100/1
2100/10
</pre>
</pre>