Task

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.

THE REAL PROGRAMMER'S NATURAL HABITAT
"Taped to the wall is a line-printer Snoopy calender for the year 1969."

Moreover this task is further inspired by the long lost corollary article titled:

"Real programmers think in UPPERCASE"!

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.




(QL:QUICKLOAD '(DATE-CALC))
 
(DEFPARAMETER *DAY-ROW* "SU MO TU WE TH FR SA")
(DEFPARAMETER *CALENDAR-MARGIN* 3)
 
(DEFUN MONTH-TO-WORD (MONTH)
  "TRANSLATE A MONTH FROM 1 TO 12 INTO ITS WORD REPRESENTATION."
  (SVREF #("JANUARY" "FEBRUARY" "MARCH" "APRIL"
           "MAY" "JUNE" "JULY" "AUGUST"
           "SEPTEMBER" "OCTOBER" "NOVEMBER" "DECEMBER")
         (1- MONTH)))
 
(DEFUN MONTH-STRINGS (YEAR MONTH)
  "COLLECT ALL OF THE STRINGS THAT MAKE UP A CALENDAR FOR A GIVEN
MONTH AND YEAR."
  `(,(DATE-CALC:CENTER (MONTH-TO-WORD MONTH) (LENGTH *DAY-ROW*))
     ,*DAY-ROW*
     ;; WE CAN ASSUME THAT A MONTH CALENDAR WILL ALWAYS FIT INTO A 7 BY 6 BLOCK
     ;; OF VALUES. THIS MAKES IT EASY TO FORMAT THE RESULTING STRINGS.
     ,@ (LET ((DAYS (MAKE-ARRAY (* 7 6) :INITIAL-ELEMENT NIL)))
          (LOOP :FOR I :FROM (DATE-CALC:DAY-OF-WEEK YEAR MONTH 1)
             :FOR DAY :FROM 1 :TO (DATE-CALC:DAYS-IN-MONTH YEAR MONTH)
             :DO (SETF (AREF DAYS I) DAY))
          (LOOP :FOR I :FROM 0 :TO 5
             :COLLECT
             (FORMAT NIL "~{~:[  ~;~2,D~]~^ ~}"
                     (LOOP :FOR DAY :ACROSS (SUBSEQ DAYS (* I 7) (+ 7 (* I 7)))
                        :APPEND (IF DAY (LIST DAY DAY) (LIST DAY))))))))
 
(DEFUN CALC-COLUMNS (CHARACTERS MARGIN-SIZE)
  "CALCULATE THE NUMBER OF COLUMNS GIVEN THE NUMBER OF CHARACTERS PER
COLUMN AND THE MARGIN-SIZE BETWEEN THEM."
  (MULTIPLE-VALUE-BIND (COLS EXCESS)
      (TRUNCATE CHARACTERS (+ MARGIN-SIZE (LENGTH *DAY-ROW*)))
    (INCF EXCESS MARGIN-SIZE)
    (IF (>= EXCESS (LENGTH *DAY-ROW*))
        (1+ COLS)
        COLS)))
 
(DEFUN TAKE (N LIST)
  "TAKE THE FIRST N ELEMENTS OF A LIST."
  (LOOP :REPEAT N :FOR X :IN LIST :COLLECT X))
 
(DEFUN DROP (N LIST)
  "DROP THE FIRST N ELEMENTS OF A LIST."
  (COND ((OR (<= N 0) (NULL LIST)) LIST)
        (T (DROP (1- N) (CDR LIST)))))
 
(DEFUN CHUNKS-OF (N LIST)
  "SPLIT THE LIST INTO CHUNKS OF SIZE N."
  (ASSERT (> N 0))
  (LOOP :FOR X := LIST :THEN (DROP N X)
     :WHILE X
     :COLLECT (TAKE N X)))
 
(DEFUN PRINT-CALENDAR (YEAR &KEY (CHARACTERS 80) (MARGIN-SIZE 3))
  "PRINT OUT THE CALENDAR FOR A GIVEN YEAR, OPTIONALLY SPECIFYING
A WIDTH LIMIT IN CHARACTERS AND MARGIN-SIZE BETWEEN MONTHS."
  (ASSERT (>= CHARACTERS (LENGTH *DAY-ROW*)))
  (ASSERT (>= MARGIN-SIZE 0))
  (LET* ((CALENDARS (LOOP :FOR MONTH :FROM 1 :TO 12
                       :COLLECT (MONTH-STRINGS YEAR MONTH)))
         (COLUMN-COUNT (CALC-COLUMNS CHARACTERS MARGIN-SIZE))
         (TOTAL-SIZE (+ (* COLUMN-COUNT (LENGTH *DAY-ROW*))
                        (* (1- COLUMN-COUNT) MARGIN-SIZE)))
         (FORMAT-STRING (CONCATENATE 'STRING
                                     "~{~A~^~" (WRITE-TO-STRING MARGIN-SIZE) ",0@T~}~%")))
    (FORMAT T "~A~%~A~%~%"
            (DATE-CALC:CENTER "[SNOOPY]" TOTAL-SIZE)
            (DATE-CALC:CENTER (WRITE-TO-STRING YEAR) TOTAL-SIZE))
    (LOOP :FOR ROW :IN (CHUNKS-OF COLUMN-COUNT CALENDARS)
       :DO (APPLY 'MAPCAR
                  (LAMBDA (&REST HEADS)
                    (FORMAT T FORMAT-STRING HEADS))
                  ROW))))