fork download
  1. (require srfi/1 srfi/13 srfi/41)
  2.  
  3. (define *calender-base*
  4. (stream-map (lambda (year)
  5. `(31 ,(if (or (zero? (modulo year 400))
  6. (and (zero? (modulo year 4))
  7. (not (zero? (modulo year 100)))))
  8. 29
  9. 28)
  10. 31 30 31 30 31 31 30 31 30 31))
  11. (stream-from 0)))
  12.  
  13. (define (make-calender year month)
  14. (let loop ((blanks (modulo
  15. (fold +
  16. (stream-fold + 0
  17. (stream-map
  18. (lambda (y)
  19. (apply + y))
  20. (stream-cdr
  21. (stream-take year *calender-base*))))
  22. (take (stream-ref *calender-base* year) (- month 1)))
  23. 7))
  24. (count 0)
  25. (days (iota (list-ref
  26. (stream-ref *calender-base* year)
  27. (- month 1)) 1))
  28. (ls '()))
  29. (cond ((null? days) (apply string-append (reverse ls)))
  30. ((= count 7) (loop blanks
  31. 0
  32. days
  33. (cons "~%" ls)))
  34. ((zero? blanks) (loop blanks
  35. (+ count 1)
  36. (cdr days)
  37. (cons (string-pad
  38. (number->string (car days))
  39. 3) ls)))
  40. (else (loop (- blanks 1)
  41. (+ count 1)
  42. days
  43. (cons " " ls))))))
Success #stdin #stdout 0.4s 78764KB
stdin
Standard input is empty
stdout
Standard output is empty