home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
p3_25dc.seq
< prev
next >
Wrap
Text File
|
1990-04-05
|
2KB
|
70 lines
\ Problem 3.25 by Dickson Cheng 04/05/90 21:12:50.93
\ (IN) leaves a true flag if a < x < b , otherwise false.
: (IN) ( x a b -- flag )
OVER 1 PICK > IF SWAP THEN
-ROT OVER < -ROT > AND ;
\ [IN] leaves a true flag if a <= x <= b
: [IN] ( x a b -- flag )
1+ SWAP 1- SWAP (IN) ;
: DIGIT? ( n -- flag )
48 ( ASCII 0 ) 57 ( ASCII 9 ) [IN] ;
: RUBOUT ( -- )
8 EMIT SPACE 8 EMIT ;
: -DIGIT ( n -- n/10 )
10 / ;
: +DIGIT ( n c -- 10n+c-48 )
48 - SWAP 10 * + ;
: #IN ( -- n )
0 BEGIN KEY
DUP 13 ( enter ) =
IF DROP EXIT THEN
DUP 8 ( backspace ) =
IF DROP RUBOUT -DIGIT
ELSE DUP DIGIT?
IF DUP EMIT
+DIGIT
ELSE DROP
7 ( bell ) EMIT
THEN
THEN
AGAIN ;
VARIABLE SEED 12345 SEED !
: (RND) SEED @ 259 * 3 + 32767 AND DUP SEED ! ;
\ r is a random number 0 <= r < n
: RND ( n -- r )
(RND) 32767 */ ;
: WINNER? ( secret old# new# -- secret old# new# flag )
2 PICK OVER = ;
: HOT? ( secret old# new# -- secred old# new# flag )
2 PICK OVER - ABS 3 < ;
: WARMER? ( secret old# new# -- secret old# new# flag )
2 PICK OVER - ABS
3 PICK 3 PICK - ABS < ;
: GUESS ( -- )
100 RND 1+ 0 \ random a number ( 0 < rnd < 100 )
\ and add a dummy old#
BEGIN CR ." GUESS " #IN SPACE \ get user input
WINNER? IF ." GOT IT" DROP 2DROP EXIT THEN \ winner ? => exit
HOT? IF ." HOT " ELSE \ hot ?
WARMER? IF ." WARMER " ELSE ." COLDER " THEN \ warmer ? or colder ?
THEN NIP \ del old#
AGAIN ; \ guess again