10-29-2013

posted Oct 29, 2013, 12:58 PM by Samuel Konstantinovich   [ updated Oct 29, 2013, 2:42 PM ]
Today's Goal: Towers of Hanoi.

Remember Homework:
Write a function that prints the hailstone series.
You should use the new functions from today:
begin
display
newline

Here are several ways to use begin/display/newline. Run+Test these functions to get an idea how they work.

(define (printList L)
  (cond
    ( (null? L) (newline) )
    ( (=(length L) 1) (begin
                        (display (car L))
                        (newline)))
    ( else (begin
             (display (car L))
             (display ", ")
             (printList (cdr L))
             ))))

(printList '(1 2 3 (4 5) 6 ))


(define (sequence N)
  (cond
    ( (<= N 1) (begin
                 (display N)
                 (display ";")
                 (newline)))
    ( else     (begin
                 (display N)
                 (display ",")
                 (sequence (/ N 2))))))

(sequence 64)


(define (sequence2 N)
  (cond
    ( (<= N 1) (begin
                 (display N)
                 (display ";")))
    ( else     (begin
                 (sequence2 (/ N 2))
                 (display N)
                 (display ",")
                 ))))

(sequence2 128)
               
Comments