Created
October 8, 2024 22:36
-
-
Save ashton314/d02cc506282e2f0ec4094fee44578a63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; f(x) = x + 1 | |
(define (f x) (+ x 1)) | |
;; g(x) = x*x + 1 | |
(define (g x) (+ (* x x) 1)) | |
(define (respond secret guess) | |
(if (= secret guess) | |
"you got it!" | |
(if (< secret guess) | |
"lower" | |
"higher"))) | |
(define (run-guess secret) | |
(printf "Give me guess: ") | |
(let ([the-guess (string->number (read-line))]) | |
(let ([the-response (respond secret the-guess)]) | |
(printf "response: ~a\n" the-response) | |
(if (equal? "you got it!" the-response) | |
"done" | |
(run-guess secret))))) | |
(define (play-game) | |
(let ([the-secret (random 100)]) | |
(run-guess the-secret))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment