10-25-2013 Lab

posted Oct 24, 2013, 8:56 PM by Samuel Konstantinovich   [ updated Oct 25, 2013, 6:06 AM ]
NOTE: Quiz on easier recursive problems Monday. No sublists on the quiz. 
DO THIS ON PAPER!
(define what? (lambda (L)
  (cond 
    ( (null? L) 0)
    ( (null? (car L)) (+ 1 (what? (cdr L))))
    ( else (what? (cdr L))))))

(define huh? (lambda (L)
  (cond 
    ( (null? L) 0)
    ( (null? (car L)) (+ 1 (huh? (cdr L))))
    ( (list? (car L)) (+ (huh? (car L))(huh? (cdr L))))
    ( else (what? (cdr L))))))

;DO THE RED QUESTIONS ON PAPER!
;1 trace each of these expressions showing one line per recursive call:
(what? '( () )      )
(what? '( (()) )    )       
(huh?  '( () )      )
(huh?  '( ( () ) )  )

;2 Determine appropriate names for 'what?' and 'huh?'



;DO THE BLUE QUESTIONS ON THE COMPUTER
;3a Write a function that counts all the elements of a list.


;3b Write a function that finds the maximum value in a list.


;Look at your countHail function, your count elements, and find max elements
;4a The current element of a list is a car and the rest is a cdr. What is the 'current element' of (countHail n) 
;4b What part of your function represents the rest of the sequence?

;5 Compare counthail to count all elements of a list. What are the similarities?
;5b Write maxHail. 
*if you already wrote a working maxhail then you rock! move on*



;*CHALLENGE PROBLEMS!* (use the computer if you wish)

;6 You wrote a GCD function. Now write a function that determines if a number N is prime. (Prime? N) is true only when N is prime, and false when N is composite. 
;You may use GCD if you wish. You may need to use a naive solution. 
;(Difficulty: At most 33% of you should be able to do this, but I dare you to prove me wrong!!!)




;7 Write a function (maxHailUpToN n) that takes a number n. It finds all the maxHail's 1-n, and tells you whicn number has the highest value in it. 
;(Difficulty: 10% of you should be able to do this)
;Example:
;hailstone 1 -> 1
;hailstone 2 -> 2 1 
;hailstone 3 -> 3 10 5 16 8 4 2 1
;hailstone 4 -> 4 2 1
;hailstone 5 -> 5 16 8 4 2 1
;hailsotne 6 is like 3.
;hailstone 7 -> 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
;(maxHailUpToN 2) -> 2 (2nd has a 2)
;(maxHailUpToN 3) -> 3 (3rd has a 16)
;(maxHailUpToN 4) -> 3 (3rd has a 16)
;(maxHailUpToN 5) -> 3 (3rd has a 16)
;(maxHailUpToN 7) -> 7 (7th has a 52)

;*challenge problem OMEGA* solve this and you earn 100 as a final grade. (Do this last)
;8 Come up with a number that will cause the hailstone sequence to not terminate. 
;(Difficulty: at most 1 of you would be able to do this, because nobody else can do it... you would be the first)


Comments