How to resolve the algorithm Find the last Sunday of each month step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Find the last Sunday of each month step by step in the Wren programming language
Table of Contents
Problem Statement
Write a program or a script that returns the last Sundays of each month of a given year. The year may be given through any simple input method in your language (command line, std in, etc). Example of an expected output:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Find the last Sunday of each month step by step in the Wren programming language
Source code in the wren programming language
import "os" for Process
import "/date" for Date
var args = Process.arguments
if (args.count != 1) {
Fiber.abort("Please pass just the year to be processed.")
}
var year = Num.fromString(args[0])
System.print("The dates of the last Sundays in the month for %(year) are:")
Date.default = Date.isoDate
for (m in 1..12) {
var d = Date.monthLength(year, m)
var dt = Date.new(year, m, d)
var wd = dt.dayOfWeek
if (wd == 7) {
System.print(dt)
} else {
System.print(dt.addDays(-wd))
}
}
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the Ruby programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Cuban primes step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Percentage difference between images step by step in the Forth programming language
You may also check:How to resolve the algorithm Semordnilap step by step in the Lasso programming language