2017-09-28

posted Sep 28, 2017, 6:23 AM by Samuel Konstantinovich   [ updated Sep 29, 2017, 5:54 AM ]

Go over any remaining problems that people had questions about.

Go over a tiny bit of recursion.

Lab: Come up with some more test cases, and verify them with your neighbor first!

1. (sortaSum a b)
Given 2 integers, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20. (sortaSum 3 4) → 7 
(sortaSum 9 4) → 20 
(sortaSum 10 11) → 21

2.  (inOrderEqual a b c equalOK)
Given three integers, a b c, return true if they are in strict increasing order (not equal), such as 2 5 11, or 5 6 7, but not 6 5 7 or 5 5 7. 
However, with the exception that if equalOK is true, equality is allowed, such as 5 5 7 or 5 5 5. 
(inOrderEqual 2  5  11 #false) → #true 
(inOrderEqual 5  7  6  #false) → #false 
(inOrderEqual 5  5  7  #true) → #true

3.  (maxMod5 a b)
Given two integer values, return whichever value is larger. 
However if the two values have the same remainder when divided by 5, then the return the smaller value. 
However, in all cases, if the two values are the same, return 0. 
(maxMod5 2 3) → 3 
(maxMod5 6 1) → 1 
(maxMod5 6 2) → 6



(define (LeapYearA year)
  (if (not (divis year 4))
      #F
      (if (not (divis year 100))
          #T
          (if (divis year 400)
              #T
              #F))))

(define (LeapYearB year)
  (cond
    ((not (divis year 4))  #F)
    ((not (divis year 100)) #T)
    ((divis year 400)#T)
    (else       #F)))
"-----"
(define (LeapYearShort year)
  (and
   (= (remainder year 4) 0)
   (or
         (not (= (remainder year 100) 0))
         (= (remainder year 400) 0))))


edit: fixed typo with parenthesis.

Comments