;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname testReview) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;;Generative
;;at-least-10?: [Listof X] -> Boolean
(define (at-least-10? lox)
(at-least-10?-help lox 0))
(check-expect (at-least-10? (build-list 9 add1)) #false)
(check-expect (at-least-10? (list 1 2 3 4 5 6 7 8 9 10)) #true)
;;at-least-10?-help: [Listof X] Number -> Boolean
;; does the list have 10 or more elements (with acc)
;;acculator: Number of elements seen so far
(define (at-least-10?-help lox numb)
(cond [(= numb 10) #true]
[(empty? lox) #false]
[else (at-least-10?-help (rest lox) (add1 numb))]))
;;Mutual
;; Pebble game
;; Alice always removes 1 pebble
;; Bob removes 2 if # pebbles is even, else 1
;; starting with n pebbles
;; and Alice starting who wins?
;; Winning = removing last pebble
;;Pebble: Number -> String
;; takes in inital # of pebbles
;; and returns winner's name
;; N > 0
(define (pebble numb)
(alice-play numb))
;;alice-play: Number -> String
;; Alice always removes 1 pebble
;; returns who wins
(define (alice-play numb)
(cond [(= 1 numb) "Alice"]
[else (bob-play (sub1 numb))]))
;;bob-play: Number -> String
;; Bob removes 2 if # pebbles is even, else 1
(define (bob-play numb)
(cond [(< numb 3) "Bob"]
[(even? numb) (alice-play (- numb 2))]
[else (alice-play (sub1 numb))]))
(check-expect (pebble 4) "Bob")
(check-expect (pebble 1) "Alice")
;;foo: [X -> Y] X [Y -> X] -> Y
(define (foo a b c)
(a (c (a b))))