How to resolve the algorithm Calendar - for REAL programmers step by step in the Tcl programming language
How to resolve the algorithm Calendar - for REAL programmers step by step in the Tcl programming language
Table of Contents
Problem Statement
Provide an algorithm as per the Calendar task, except the entire code for the algorithm must be presented entirely without lowercase.
Also - as per many 1969 era line printers - format the calendar to nicely fill a page that is 132 characters wide.
(Hint: manually convert the code from the Calendar task to all UPPERCASE)
This task also is inspired by Real Programmers Don't Use PASCAL by Ed Post, Datamation, volume 29 number 7, July 1983.
Moreover this task is further inspired by the long lost corollary article titled:
Note: Whereas today we only need to worry about ASCII, UTF-8, UTF-16, UTF-32, UTF-7 and UTF-EBCDIC encodings, in the 1960s having code in UPPERCASE was often mandatory as characters were often stuffed into 36-bit words as 6 lots of 6-bit characters. More extreme words sizes include 60-bit words of the CDC 6000 series computers. The Soviets even had a national character set that was inclusive of all
4-bit,
5-bit,
6-bit &
7-bit depending on how the file was opened... And one rogue Soviet university went further and built a 1.5-bit based computer.
Of course... as us Boomers have turned into Geezers we have become HARD OF HEARING,
and suffer from chronic Presbyopia, hence programming in UPPERCASE
is less to do with computer architecture and more to do with practically. :-)
For economy of size, do not actually include Snoopy generation
in either the code or the output, instead just output a place-holder.
FYI: a nice ASCII art file of Snoopy can be found at textfiles.com. Save with a .txt extension.
Trivia: The terms uppercase and lowercase date back to the early days of the mechanical printing press. Individual metal alloy casts of each needed letter, or punctuation symbol, were meticulously added to a press block, by hand, before rolling out copies of a page. These metal casts were stored and organized in wooden cases. The more often needed minuscule letters were placed closer to hand, in the lower cases of the work bench. The less often needed, capitalized, majuscule letters, ended up in the harder to reach upper cases.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Calendar - for REAL programmers step by step in the Tcl programming language
Source code in the tcl programming language
\146\157\162\145\141\143\150 42 [\151\156\146\157 \143\157\155\155\141\156\144\163] {
\145\166\141\154 "
\160\162\157\143 [\163\164\162\151\156\147 \164\157\165\160\160\145\162 $42] {\141\162\147\163} \{
\163\145\164 \151 1
\146\157\162\145\141\143\150 \141 \$\141\162\147\163 \{
\151\146 \[\163\164\162\151\156\147 \155\141\164\143\150 _ \$\141\] \{\151\156\143\162 \151; \143\157\156\164\151\156\165\145\}
\151\146 \$\151%2 \{\154\141\160\160\145\156\144 \156\141\162\147\163 \[\163\164\162\151\156\147 \164\157\154\157\167\145\162 \$\141\]\} \{\154\141\160\160\145\156\144 \156\141\162\147\163 \$\141\}
\}
\165\160\154\145\166\145\154 \"$42 \$\156\141\162\147\163\"
\}
"
}
PROC _ CPUTS {L S} {
UPVAR _ CAL CAL
APPEND _ CAL($L) $S
}
PROC _ CENTER {S LN} {
SET _ C [STRING LENGTH $S]
SET _ L [EXPR _ ($LN-$C)/2]; SET _ R [EXPR _ $LN-$L-$C]
FORMAT "%${L}S%${C}S%${R}S" _ "" $S ""
}
PROC _ CALENDAR {{YEAR 1969} {WIDTH 80}} {
ARRAY SET CAL ""
SET _ YRS [EXPR $YEAR-1584]
SET _ SDAY [EXPR (6+$YRS+(($YRS+3)/4)-(($YRS-17)/100+1)+(($YRS+383)/400))%7]
CPUTS 0 [CENTER "(SNOOPY)" [EXPR $WIDTH/25*25]]; CPUTS 1 ""
CPUTS 2 [CENTER "--- $YEAR ---" [EXPR $WIDTH/25*25]]; CPUTS 3 ""
FOR _ {SET _ NR 0} {$NR<=11} {INCR _ NR} {
SET _ LINE [EXPR ($NR/($WIDTH/25))*8+4]
SET _ NAME [LINDEX _ "JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER" $NR]
SET _ DAYS [EXPR 31-((($NR)%7)%2)-($NR==1)*(2-((($YEAR%4==0)&&($YEAR%100>0))||($YEAR%400==0)))]
CPUTS $LINE "[CENTER $NAME 20] "
CPUTS [INCR _ LINE] "MO TU WE TH FR SA SU "; INCR _ LINE
SET _ DAY [EXPR 1-$SDAY]
FOR _ {SET _ X 0} {$X<42} {INCR _ X} {
IF _ ($DAY>0)&&($DAY<=$DAYS) {CPUTS $LINE [FORMAT "%2d " $DAY]} {CPUTS $LINE " "}
IF _ (($X+1)%7)==0 {CPUTS $LINE " "; INCR _ LINE}
INCR _ DAY
}
SET _ SDAY [EXPR ($SDAY+($DAYS%7))%7]
}
FOR _ {SET _ X 0} {$X<[ARRAY SIZE _ CAL]} {INCR _ X} {
PUTS _ $CAL($X)
}
}
CALENDAR
You may also check:How to resolve the algorithm Damm algorithm step by step in the zkl programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Excel programming language
You may also check:How to resolve the algorithm String prepend step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Factorial step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Generic swap step by step in the D programming language