10-23-2013 Lab

posted Oct 23, 2013, 5:38 AM by Samuel Konstantinovich   [ updated Oct 24, 2013, 8:22 AM ]
Do Now:
1.Open your functions from yesterday and run them on these examples: (Stop typing, do not edit your code)
(countEvenSub '( 1 ( ) (2 3) (4 (5 6) ) ) )
(countSublists '( 1 ( ) (2 3) (4 (5 6) ) ) )
(countSublists '( 1 ( 2 3) ( (4) (5)) (6 (7 8) ) ) )

Lab/HW:
2. In pairs: Put both your names on one piece of paper, and write your notes/ideas/functions on that paper.
Idea:
Fibonacci costs a lot to run. For all non negative fib numbers:
(define (fib n) (cond
    ( (= 0 n) 1)
    ( (= 1 n) 1)
    ( else  (+ (fib (- n 1)) (fib (- n 2))))
))
Lets assume that: 
    every +,- operator costs $1.00
    and every comparison like <,>,= costs $0.02.
This means:
(fib 0) -> costs 0.02 because it runs the 1st = operator, then stops.
(fib 1) -> costs 0.02 + 0.02 because it runs the 1st =, then the 2nd =, then stops.
(fib 2) -> costs 0.02 + 0.02 + 3.00 + the cost of the recursive calls.
Your job:
1. Come up with a relationship that expresses this cost. You have to be able to describe it before writing code.
2. Write the code outline on paper. 
3. Write the code on the computer, alternating who types every 5 minutes. Email the code to both people for your records. 


After checking HW:
Go over lab from yesterday.
Demonstration of using higher order functions to make the functions more readable:

Comments