(C Series?) Guessing Game 14

04272018, 06:49 PM
(This post was last modified: 04272018 07:09 PM by SamE.)
Post: #1




(C Series?) Guessing Game 14
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 Trying to hide their hp obsession from their friends. 

04272018, 07:34 PM
(This post was last modified: 04272018 07:44 PM by Dieter.)
Post: #2




RE: (C Series?) Guessing Game 14
(04272018 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? (04272018 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 

04272018, 08:49 PM
Post: #3




RE: (C Series?) Guessing Game 14
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. 

04272018, 09:48 PM
(This post was last modified: 04272018 09:52 PM by Dieter.)
Post: #4




RE: (C Series?) Guessing Game 14
(04272018 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# 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 

« Next Oldest  Next Newest »

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