;; 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)))
;; Boolean Boolean -> Boolean
(define xor
(λ(a b)
(and (or a b)
(not (and a b)))))
; Integer Integer -> Boolean
; Assume d is not zero.
(define divisor?
(λ(n d)
(and (not (zero? d))
(zero? (remainder n d)))))
;; Integer -> Boolean
(define leap-year?
(λ(year)
(or (divisor? year 400)
(xor (divisor? year 4)
(divisor? year 100)))))
;; String Integer Integer -> String
;; m : "January", "February", ..., "Decemeber"
;; d : 1 <= d <= 31
;; y : represents a year
;(define day-of-date
; (λ(month day year)
;; String -> Integer
;; Assume month is one of : "January", ..., "December"
(define month-key
(λ(month)
(cond ((or (equal? month "April")
(equal? month "July")) 0)
((or (equal? month "January")
(equal? month "October")) 1)
((equal? month "May") 2)
((equal? month "August") 3)
((or (equal? month "February")
(equal? month "March")
(equal? month "November")) 4)
((equal? month "June") 5)
(else 6))))
;; Integer -> Integer
; 1699 < 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."))))
(day-of-date "March" 5 2014)