Skip to content

Instantly share code, notes, and snippets.

@ashton314
Created October 8, 2024 22:36
Show Gist options
  • Save ashton314/d02cc506282e2f0ec4094fee44578a63 to your computer and use it in GitHub Desktop.
Save ashton314/d02cc506282e2f0ec4094fee44578a63 to your computer and use it in GitHub Desktop.
#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