summaryrefslogtreecommitdiffstats
path: root/chapter2
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-07-03 15:49:09 -0400
committerrsiddharth <s@ricketyspace.net>2020-07-03 15:49:09 -0400
commit9d23e66fe8332abc7a1bbd9022f3e58e1133b3fb (patch)
tree5bf435cd979dcb785624d43c75f379ae684f97e3 /chapter2
parent0f072be231d0bd875d1c87ff127834e60979263a (diff)
name directories like the realm repo.
Diffstat (limited to 'chapter2')
-rw-r--r--chapter2/guess.rkt21
1 files changed, 21 insertions, 0 deletions
diff --git a/chapter2/guess.rkt b/chapter2/guess.rkt
new file mode 100644
index 0000000..ab05056
--- /dev/null
+++ b/chapter2/guess.rkt
@@ -0,0 +1,21 @@
+#lang racket
+
+(define lower 1)
+
+(define upper 100)
+
+(define (start n m)
+ (set! lower (min n m))
+ (set! upper (max n m))
+ (guess))
+
+(define (guess)
+ (quotient (+ lower upper) 2))
+
+(define (smaller)
+ (set! upper (max lower (sub1 (guess))))
+ (guess))
+
+(define (bigger)
+ (set! lower (min upper (add1 (guess))))
+ (guess))