Post Reply 
(C Series?) Guessing Game 1-4
04-27-2018, 06:49 PM (This post was last modified: 04-27-2018 07:09 PM by SamE.)
Post: #1
(C Series?) Guessing Game 1-4
I made this a while back as a test of my skills. It's probably incredibly sloppy, but it works. I'm not sure what devices this works on exactly as I only have an 11C.
Code:
LBL A
RAND #
ENTER
1
0
*
INT
4
X<>Y
X≤Y
GTO 1
GTO A
LBL 1
STO 1
CLX
RTN
LBL B
ENTER
RCL 1
X=Y
GTO 2
GTO 3
LBL 2
RCL 2
ENTER
1
+
STO 2
PSE
GTO A
LBL 3
RCL 2
ENTER
1
-
X<0
GTO 4
STO 2
PSE
GTO A
LBL 4
1
+
STO 2
PSE
GTO A
You press A to initiate the game, input your guess, then press B. The number of points you have will appear, then you will be able to input another guess. The answer will only be 1-4, other numbers will just subtract from your points.

Trying to hide their hp obsession from their friends.
Find all posts by this user
Quote this message in a reply
04-27-2018, 07:34 PM (This post was last modified: 04-27-2018 07:44 PM by Dieter.)
Post: #2
RE: (C Series?) Guessing Game 1-4
(04-27-2018 06:49 PM)SamE Wrote:  I made this a while back as a test of my skills. It's probably incredibly sloppy, but it works.

Yes, there is plenty room for improvement. But since this is an old program of yours ("a while back") I assume your skills will have improved by now. So how would you code this today?

(04-27-2018 06:49 PM)SamE Wrote:  I'm not sure what devices this works on exactly as I only have an 11C.

It should work on most HPs with a RAN# function. If you insert your own random number generator this should even include most programmable calculators. Maybe after renaming the labels A and B and/or use line addressing, and replacing X=Y? with X=0? after X and Y have been subtracted. The X<0? may take some care on calculators that do not have such a test, but it can be done.

Regarding the program: may I ask two questions?

The program is supposed to generate a number between 1 and 4. But in fact the number can be between 0 and 4. ?!?

The program first calculates a random integer between 0 and 9. Then it checks if it is ≤ 4. If not, it is discarded and a new number is calculated. But... why doesn't the program simply directly calculate a number between 0 or 1 and 4 ?

Sorry if I didn't understand something here, but I just want to ask.

Dieter
Find all posts by this user
Quote this message in a reply
04-27-2018, 08:49 PM
Post: #3
RE: (C Series?) Guessing Game 1-4
Actually, I failed to realize until you told me that that it calculated between zero and four. And I'm not sure if there's a way to just calculate a number between one and four from the RAN# function, I'm working with the knowledge I have.

Trying to hide their hp obsession from their friends.
Find all posts by this user
Quote this message in a reply
04-27-2018, 09:48 PM (This post was last modified: 04-27-2018 09:52 PM by Dieter.)
Post: #4
RE: (C Series?) Guessing Game 1-4
(04-27-2018 08:49 PM)SamE Wrote:  Actually, I failed to realize until you told me that that it calculated between zero and four. And I'm not sure if there's a way to just calculate a number between one and four from the RAN# function, I'm working with the knowledge I have.

If there is a way to calculate a number between 0 and 9 there also is a way to calculate one between 0 and 4. Or 1 and 4, for that matter. ;-)

(1) RAN# returns a random number between 0 and 0,9999...
(2) Multiply this by 4 and you get something between 0 and 3,9999...
(3) Take the integer part and get an integer between 0 and 3.
(4) Add 1 and get the desired result between 1 and 4.

So it's

Code:
RAN#
4
x
INT
1
+

Note: There is a tiny problem due to numeric limiations that may cause step (2) to return 4 instead of 3,9999..., but let's forget about this here – the chance for this to happen is 1 : 10 000 000 000.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)