Skip to content

Instantly share code, notes, and snippets.

@futureperfect
Created July 11, 2016 20:43
Show Gist options
  • Save futureperfect/4978607713bd0beeb98464a6109811b7 to your computer and use it in GitHub Desktop.
Save futureperfect/4978607713bd0beeb98464a6109811b7 to your computer and use it in GitHub Desktop.
Ch2 Realm of Racket
#lang racket
(define lower-bound 1)
(define upper-bound 100)
(define (start n m)
(set! lower-bound (min n m))
(set! upper-bound (max n m))
(guess))
(define (guess)
(quotient (+ lower-bound upper-bound) 2))
(define (smaller)
(set! upper-bound (max lower-bound (sub1 (guess))))
(guess))
(define (bigger)
(set! lower-bound (min upper-bound (add1 (guess))))
(guess))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment