Paste: Guessing Game
Author: | Capital |
Mode: | factor |
Date: | Tue, 5 Sep 2023 19:03:21 |
Plain Text |
USING: combinators io kernel math.order math.parser random
ranges ;
IN: simple-guessing-game
: intro ( -- )
"I'm thinking of a number between 1 and 100" print ;
: pick-number ( -- n )
100 [1..b] random ;
: read-number ( -- n )
"Enter a guess: " write readln dec> ;
: guessing-game ( n -- )
dup read-number <=> {
{ +lt+ [ "Too high!" print t ] }
{ +gt+ [ "Too low!" print t ] }
[ drop "You won!" print f ]
} case [ guessing-game ] [ drop ] if ;
MAIN: [
intro
pick-number
guessing-game
]
New Annotation