How to resolve the algorithm Calendar step by step in the M2000 Interpreter programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Calendar step by step in the M2000 Interpreter programming language
Table of Contents
Problem Statement
Create a routine that will generate a text calendar for any year.
Test the calendar by generating a calendar for the year 1969, on a device of the time.
Choose one of the following devices:
(Ideally, the program will generate well-formatted calendars for any page width from 20 characters up.) Kudos (κῦδος) for routines that also transition from Julian to Gregorian calendar. This task is inspired by Real Programmers Don't Use PASCAL by Ed Post, Datamation, volume 29 number 7, July 1983. For further Kudos see task CALENDAR, where all code is to be in UPPERCASE. For economy of size, do not actually include Snoopy generation in either the code or the output, instead just output a place-holder.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Calendar step by step in the M2000 Interpreter programming language
Source code in the m2000 programming language
Module Calendar (Year, LocaleId) {
Function GetMax(Year, Month) {
a=date(str$(Year)+"-"+str$(Month)+"-1")
max=32
do {
max--
m=val(str$(cdate(a,0,0,max), "m"))
} until m=Month
=max+1
}
Function SkipMo(Year, Month) {
a=date(str$(Year)+"-"+str$(Month)+"-1")
=(val(str$(a, "w"))-8) mod 7 +7
}
Function Title$(a$) {
=Ucase$(left$(a$,1))+Lcase$(Mid$(a$, 2))
}
locale LocaleId
Cursor 0,Height-1 ' last line, so each new line scroll all lines up
Print Over $(2), Year
Print
For j=0 to 3 {
Print
For i=1 to 3 {
Month=i+j*3
Print Part @((i-1)*29-1), $(2,22), Title$(Ucase$(locale$(55+Month)))
}
Print
Dim Skip(1 to 3), Count(1 to 3), D(1 to 3)=1
For i=1 to 3 {
Month=i+j*3
if i>1 Then Print String$(" ",8);
For k=42 to 48 :Print Title$(Ucase$(Left$(locale$(k),2)));" ";:Next k
Skip(i)=SkipMo(Year, Month)
Count(i)=GetMax(Year, Month)
}
Print
For i=1 to 3 {
if i>1 Then Print String$(" ",8);
For k=1 to 7 {
skip(i)--
if skip(i)>0 Then Print " "; :continue
Count(i)--
Print format$("{0::-2} ", d(i));
d(i)++
}
}
Print
Print @(0)
For m=1 to 5 {
For i=1 to 3 {
if i>1 Then Print String$(" ",8);
For k=1 to 7 {
Count(i)--
if Count(i)<0 Then Print " "; : Continue
Print format$("{0::-2} ", d(i));
d(i)++
}
}
Print
}
}
}
Form 80,43
Calendar 1969, 1033 ' English
k=Key$ ' wait key
Calendar 2018, 1032 ' Greek
You may also check:How to resolve the algorithm Diversity prediction theorem step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Mutex step by step in the Phix programming language
You may also check:How to resolve the algorithm Introspection step by step in the Pop11 programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the ProDOS programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Seed7 programming language