;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname day-of-date) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;; Integer Integer -> Boolean
; Assume d != 0.
(define divisor?
(λ(n d)
(= (remainder n d) 0)))
;; Integer -> Boolean
(define leap-year?
(λ(y)
(and (divisor? y 400)
(and (divisor? y 4)
(not (divisor? y 100))))))
;; String -> Integer
; Assume m is one of : January, ..., December
(define month-key
(λ(m)
(cond ((equal? m "January") 1)
((equal? m "February") 4)
((equal? m "March") 4)
((equal? m "April") 0)
((equal? m "May") 2)
((equal? m "June") 5)
((equal? m "July") 0)
((equal? m "August") 3)
((equal? m "October") 1)
((equal? m "November") 4)
(else 6)))) ;; September and December
;; Integer -> Integer
;; Assume 1700 <= year < 3000
(define century-code
(λ(year)
(cond ((< year 1800) 4)
((< year 1900) 2)
((< year 2000) 0)
(else 6))))
;; Integer -> String
; Assume 0 <= n <= 6.
(define num-to-day
(λ(n)
(cond ((= n 0) "Sat.")
((= n 1) "Sun.")
((= n 2) "Mon.")
((= n 3) "Tues.")
((= n 4) "Wed.")
((= n 5) "Thurs.")
(else "Fri."))))
;; String Integer Integer -> String
; Assume m is one of : January, ..., December
; 1 <= d <= 31
; 1699 < y < 3000
(define day-of-date
(λ(m d y)
(num-to-day (remainder (+ (quotient (remainder y 100) 4)
d
(month-key m)
(if (and (or (equal? m "January") (equal? m "February"))
(leap-year? y))
-1
0)
(century-code y)
(remainder y 100))
7))))
(day-of-date "March" 5 2014)