How to resolve the algorithm Last Friday of each month step by step in the AutoHotkey programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Last Friday of each month step by step in the AutoHotkey programming language

Table of Contents

Problem Statement

Write a program or a script that returns the date of the last Fridays 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 Last Friday of each month step by step in the AutoHotkey programming language

Source code in the autohotkey programming language

if 1 = ; no parameter passed
{
	InputBox, 1, Last Fridays of year, Enter a year:, , , , , , , , %A_YYYY%
	If ErrorLevel
		ExitApp
}

YYYY = %1% ; retrieve command line parameter
Stmp = %YYYY%0101000000
count= 0

While count < 12
{
	FormatTime, ddd, %stmp%, ddd
	FormatTime, M, %stmp%, M
	If (ddd = "Fri"){
		if (M-1 = count){
			t := stmp
			stmp += 7, days
		}
		else
			 res .= SubStr(t, 1, 4) "-" SubStr(t, 5, 2) "-" SubStr(t, 7, 2) "`n"
			,count++
			,stmp := YYYY . SubStr("0" M, -1) . "01"
	}
	else
		stmp += 1, days
}
MsgBox % res


  

You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the Perl programming language
You may also check:How to resolve the algorithm Function composition step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm General FizzBuzz step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm MD5 step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Fortran programming language