guess.cmn 600 B

123456789101112131415161718192021222324252627282930313233343536
  1. # simple guess a number game
  2. # reads one character, skipping control chars (newlines and such)
  3. readChar:
  4. @@
  5. <-
  6. $0 " " >= ? # space char is lowest "normal" char
  7. !@
  8. ;
  9. ^
  10. .
  11. .
  12. .
  13. 0 10 "Please enter a seed character for my pseudo random number generator:" -->
  14. readChar
  15. 11 * 3 + 13 * 1 + 17 * 2 + 10 % "0" + # convert to pseudorandom "0" to "9" value
  16. $0 # duplicate it for writing out in case of bad guess
  17. 0 10 "I am thinking a number from 0 to 9 (including), type your guess:" -->
  18. readChar
  19. = ?
  20. 0 "You guessed it!" -->
  21. ;
  22. 0 "No, it was " -->
  23. -> "." ->
  24. .
  25. 10 ->