How to resolve the algorithm Five weekends step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Five weekends step by step in the Arturo 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 Arturo programming language

Source code in the arturo programming language

longMonths: [1 3 5 7 8 10 12]
dates: []

yearsWithout: 0

loop 1900..2100 'year [
    found?: false
    loop longMonths 'month [
        dt: to :date .format:"d-M-YYYY" ~"1-|month|-|year|"
        if friday? dt [
            'dates ++ @[@[dt\Month year]]
            found?: true
        ]
    ]
    if not? found? ->
        inc 'yearsWithout 
]

print.lines map first.n:5 dates 'd -> ~"|to :string d\0|, |to :string d\1|"
print "..."
print.lines map last.n:5 dates 'd -> ~"|to :string d\0|, |to :string d\1|"

print ""
print ["Found" size dates "months in total."]
print ["There are" yearsWithout "years without any month that has 5 full weekends."]


  

You may also check:How to resolve the algorithm Arena storage pool step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Loops/While step by step in the PL/I programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Pick random element step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Write entire file step by step in the ALGOL 68 programming language