Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/guess.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ (c) 1994,2004 HanSoft & Partners; Guessing game 4tH

[needs lib/enter.4th]

: guesses                              ( n --)
  random 10 mod 1+ swap                \ random number
  ." Guess a number between 1 and 10" cr 
  begin                                \ repeat n times
    dup                                \ check number of guesses
  while                                \ when ok
    over enter                         \ get a number
    over over = abort" Guessed!"       \ abort when guessed
    ." Too " > if ." small" else ." big" then cr 1-
  repeat                               \ error if not guessed
  drop ." You didn't guess it, it was " . cr
;

3 guesses

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].