How to resolve the algorithm Five weekends step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Five weekends step by step in the Quackery 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 Quackery programming language
Source code in the quackery programming language
[ over 3 < if [ 1 - ]
dup 4 / over +
over 100 / -
swap 400 / +
swap 1 -
[ table
0 3 2 5 0 3
5 1 4 6 2 4 ]
+ + 7 mod ] is dayofweek ( day month year --> weekday )
[ 1 -
[ table
$ "January" $ "February"
$ "March" $ "April"
$ "May" $ "June"
$ "July" $ "August"
$ "September" $ "October"
$ "November" $ "December" ]
do ] is monthname ( monthnumber --> $ )
[] [] temp put
201 times
[ true temp put
i^ 1900 +
' [ 1 3 5 7 8 10 12 ]
witheach
[ 2dup swap
1 unrot dayofweek
5 = iff
[ false temp replace
over join nested
swap dip join ]
else drop ]
temp take iff
[ temp take
swap join
temp put ]
else drop ]
temp take swap
say "There are "
dup size echo
say " months with five weekends."
cr cr
5 split swap
say "Five weekends: "
witheach
[ do swap
monthname echo$
sp echo
i if say ", " ]
cr say " ..."
cr space 15 of echo$
-5 split nip
witheach
[ do swap
monthname echo$
sp echo
i if say ", " ]
cr cr
say "Years without five weekends: "
witheach
[ echo
i if say ", "
i^ 8 mod 7 = if
[ cr space 29 of echo$ ] ]
You may also check:How to resolve the algorithm Loops/Increment loop index within loop body step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Déjà Vu programming language
You may also check:How to resolve the algorithm Anagrams step by step in the Elena programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the OCaml programming language
You may also check:How to resolve the algorithm Input loop step by step in the FutureBasic programming language