Tagged as HTDP, LISP, Self-Learning
Written on 2008-05-19 13:43:29
As promised, here’s Section 03 with 04 soon to follow. Sections 03 and 04 are pretty unremarkable and the questions and answers are pretty self-explanatory. Again, you can check all the latest code in my repo by going to manifest, then books, htdp, and navigating to the various source files.
(define (attendees ticket-price)
(- 870 (* 150 ticket-price)))
(define (revenue ticket-price)
(* (attendees ticket-price) ticket-price))
(define (costs ticket-price)
(+ 180 (* .04 (attendees ticket-price))))
(define (profit ticket-price)
(- (revenue ticket-price) (costs ticket-price)))
(define (profit ticket-price)
(- (revenue ticket-price)
(cost ticket-price)))
(define (revenue ticket-price)
(* (attendees ticket-price) ticket-price))
(define (cost ticket-price)
(* 1.5 (attendees ticket-price)))
(define (attendees ticket-price)
(+ 120
(* (/ 15 .10) (- 5.00 ticket-price))))
(define (profit price)
(- (* (+ 120
(* (/ 15 .10)
(- 5.00 price)))
price)
(* 1.5
(+ 120
(* (/ 15 .10)
(- 5.00 price))))))
(define fixed-costs 180)
(define price-per-attendee .04)
(define start-attendees 120)
(define attendees-per-dime 15)
(define dime .10)
(define start-price 5.00)
(define inches-in-cm 2.54)
(define inches-in-ft 12)
(define feet-in-yard 3)
(define yards-in-rod 5.5)
(define rods-in-furlong 40)
(define furlongs-in-mile 8)
(define (inches->cm inches)
(* inches-in-cm inches))
(define (feet->inches feet)
(* inches-in-ft feet))
(define (yards->feet yards)
(* feet-in-yard yards))
(define (rods->yards rods)
(* yards-in-rod rods))
(define (furlongs->rods furlongs)
(* rods-in-furlong furlongs))
(define (miles->furlongs miles)
(* furlongs-in-mile miles))
(define (feet->cm feet)
(inches->cm (feet->inches feet)))
(define (yards->cm yards)
(feet->cm (yards->feet yards)))
(define (rods->inches rods)
(feet->inches (yards->feet (rods->yards rods))))
(define (miles->feet miles)
(yards->feet (rods->yards (furlongs->yards
(miles-furlongs miles)))))
(define pi 3.14159)
(define (volume-cylinder radius height)
(* pi (sqr radius) height))
(define pi 3.14159)
(define (area-cylinder radius height)
(* 2 pi radius (+ radius height)))
(define (area-pipe inner-radius length thickness)
(+ (* 2 pi length (+ inner-radius thickness))
(* 2 (- (* pi (+ inner-radius thickness))
(* pi inner-radius)))))
(define (area-pipe inner-radius length thickness)
(+ (area-pipe-side inner-radius length thickness)
(* 2 (area-pipe-ring inner-radius thickness))))
(define (area-pipe-side inner-radius length thickness)
(* 2 pi length (+ inner-radius thickness)))
(define (area-pipe-ring inner-radius thickness)
(* 2 (- (* pi (+ inner-radius thickness))
(* pi inner-radius))))
(define (height time)
(* .5 time (speed time)))
(define (speed time acceleration)
(* time acceleration))
(define (Celsius->Fahrenheit cels)
(+ 32 (/ (* cels 9) 5)))
(I 32)
(Celsius->Fahrenheit (Fahrenheit->Celsius 32))
(Celsius->Fahrenheit (* (- 32 32) (/ 5 9)))
(Celsius->Fahrenheit (* 0 (/ 5 9)))
(Celsius->Fahrenheit 0)
(+ 32 (/ (* 0 9) 5))
(+ 32 (/ 0 5))
(+ 32 0)
32