Skip to content

Instantly share code, notes, and snippets.

@tormaroe
Created March 24, 2014 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tormaroe/9749438 to your computer and use it in GitHub Desktop.
Save tormaroe/9749438 to your computer and use it in GitHub Desktop.
My implementation in Scheme of the game Kinema, that was published in BASIC Computer Games in 1978.
(use srfi-13 extras)
(printf #<<EOF
KINEMA
Adaption of BASIC computer game from 1978
EOF
)
(define correct-count)
(define (prompt-and-evaluate-answer question answer)
(display question)
(display "? ")
(let ((G (read)))
(if (> .15 (abs (/ (- G answer) answer)))
(begin
(display "Close enough.")
(set! correct-count (+ correct-count 1)))
(display "Not even close...."))
(printf "Correct answer is ~A\n" answer)))
(define (main)
(newline) (newline)
(let* ((velocity (+ 5 (random 35)))
(time (/ (+ 1 (* 2 (random velocity))) 10)))
(set! correct-count 0)
(printf
"A ball is thrown upwars at ~A meters per second.\n\n"
velocity)
(prompt-and-evaluate-answer
"How high will it go (in meters)"
(* .05 (* velocity velocity)))
(prompt-and-evaluate-answer
"How long until it returns (in seconds)"
(/ velocity 5))
(prompt-and-evaluate-answer
(sprintf "What will its velocity be after ~A seconds" time)
(- velocity (* 10 time)))
(printf "\n~A right out of 3." correct-count)
(when (> correct-count 2) (display " not bad!"))
(main)))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment