41
29 Guess the number
Assume you wish to guess a randomly chosen number between 1 and 1000.
Simple guessing will require, on average, 500 tries to find the answer.
This program will tell you if your guess is larger or smaller than a number (which it chooses),
so that, proceeding logically, it should be possible to find the answer within 11 attempts.
Program
1000Ran#+l→X:?→A:0→D:Lbl 1:D+1→D:A=X⇒Goto
3:X > A ⇒ G o t o 2:? → A:G o t o 1:L b l 2:? → B:B → A:G o t o 1:
Lbl 3:X D < 68 STEP >
Running the Program
Enter a random number and press .
If the answer is smaller than the number you entered,
“A?” will be displayed.
If the answer is larger than the number you entered,
“B?” will be displayed.
When the number you enter is the correct answer,
“X” will be displayed, along with the answer
ff
and the number of attempts made.
Prog
1
EXE
S A
R
P1
P2 P3 P4
G
S A
R
P1
P2 P3 P4
G
Disp
S A
R
P1
P2 P3 P4
G
Disp
S A
R
P1
P2 P3 P4
G
関数電卓事例集 .book 41 ページ 2002年9月2日 月曜日 午後6時51分