(require srfi/1 srfi/13 srfi/41)
(define *calender-base*
(stream-map (lambda (year)
`(31 ,(if (or (zero? (modulo year 400))
(and (zero? (modulo year 4))
(not (zero? (modulo year 100)))))
29
28)
31 30 31 30 31 31 30 31 30 31))
(stream-from 0)))
(define (make-calender year month)
(let loop ((blanks (modulo
(fold +
(stream-fold + 0
(stream-map
(lambda (y)
(apply + y))
(stream-cdr
(stream-take year *calender-base*))))
(take (stream-ref *calender-base* year) (- month 1)))
7))
(count 0)
(days (iota (list-ref
(stream-ref *calender-base* year)
(- month 1)) 1))
(ls '()))
(cond ((null? days) (apply string-append (reverse ls)))
((= count 7) (loop blanks
0
days
(cons "~%" ls)))
((zero? blanks) (loop blanks
(+ count 1)
(cdr days)
(cons (string-pad
(number->string (car days))
3) ls)))
(else (loop (- blanks 1)
(+ count 1)
days
(cons " " ls))))))
KHJlcXVpcmUgc3JmaS8xIHNyZmkvMTMgc3JmaS80MSkKCihkZWZpbmUgKmNhbGVuZGVyLWJhc2UqCiAgKHN0cmVhbS1tYXAgKGxhbWJkYSAoeWVhcikKICAgICAgICAgICAgICAgIGAoMzEgLChpZiAob3IgKHplcm8/IChtb2R1bG8geWVhciA0MDApKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgIChhbmQgKHplcm8/IChtb2R1bG8geWVhciA0KSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKG5vdCAoemVybz8gKG1vZHVsbyB5ZWFyIDEwMCkpKSkpCiAgICAgICAgICAgICAgICAgICAgICAgICAyOQogICAgICAgICAgICAgICAgICAgICAgICAgMjgpCiAgICAgICAgICAgICAgICAgICAgMzEgMzAgMzEgMzAgMzEgMzEgMzAgMzEgMzAgMzEpKQogICAgICAgICAgICAgKHN0cmVhbS1mcm9tIDApKSkKCihkZWZpbmUgKG1ha2UtY2FsZW5kZXIgeWVhciBtb250aCkKICAobGV0IGxvb3AgKChibGFua3MgKG1vZHVsbwogICAgICAgICAgICAgICAgICAgICAgKGZvbGQgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAoc3RyZWFtLWZvbGQgKyAwCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzdHJlYW0tbWFwCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAobGFtYmRhICh5KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoYXBwbHkgKyB5KSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzdHJlYW0tY2RyCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHN0cmVhbS10YWtlIHllYXIgKmNhbGVuZGVyLWJhc2UqKSkpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAodGFrZSAoc3RyZWFtLXJlZiAqY2FsZW5kZXItYmFzZSogeWVhcikgKC0gbW9udGggMSkpKQogICAgICAgICAgICAgICAgICAgICAgNykpCiAgICAgICAgICAgICAoY291bnQgMCkKICAgICAgICAgICAgIChkYXlzIChpb3RhIChsaXN0LXJlZgogICAgICAgICAgICAgICAgICAgICAgICAgIChzdHJlYW0tcmVmICpjYWxlbmRlci1iYXNlKiB5ZWFyKQogICAgICAgICAgICAgICAgICAgICAgICAgICgtIG1vbnRoIDEpKSAxKSkKICAgICAgICAgICAgIChscyAnKCkpKQogICAgKGNvbmQgKChudWxsPyBkYXlzKSAoYXBwbHkgc3RyaW5nLWFwcGVuZCAocmV2ZXJzZSBscykpKQogICAgICAgICAoKD0gY291bnQgNykgKGxvb3AgYmxhbmtzCiAgICAgICAgICAgICAgICAgICAgICAgICAgIDAKICAgICAgICAgICAgICAgICAgICAgICAgICAgZGF5cwogICAgICAgICAgICAgICAgICAgICAgICAgICAoY29ucyAifiUiIGxzKSkpCiAgICAgICAgICgoemVybz8gYmxhbmtzKSAobG9vcCBibGFua3MKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCsgY291bnQgMSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGNkciBkYXlzKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoY29ucyAoc3RyaW5nLXBhZAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKG51bWJlci0+c3RyaW5nIChjYXIgZGF5cykpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAzKSBscykpKQogICAgICAgICAoZWxzZSAobG9vcCAoLSBibGFua3MgMSkKICAgICAgICAgICAgICAgICAgICAoKyBjb3VudCAxKQogICAgICAgICAgICAgICAgICAgIGRheXMKICAgICAgICAgICAgICAgICAgICAoY29ucyAiICAgIiBscykpKSkpKQ==