(11C) Random Move
|
01-03-2019, 08:55 AM
(This post was last modified: 01-03-2019 02:24 PM by Gamo.)
Post: #1
|
|||
|
|||
(11C) Random Move
This program simulate the Random Walk by observing the digit #8
Frist initialize screen display 1,111,111,111 When run the screen display 1,111,181,111 then Number 8 will move randomly one digit left, right or stay put until it move out of the screen either left or right edge and fall off. -------------------------------------------- Procedure: [A] Initialize display 1,111,111,111 [B] display 1,111,181,111 then #8 will randomly move until fall off the screen !! Once you catch the #8 that fall out then Display show the Total Move. -------------------------------------------- Program: FIX 9 Code:
Gamo |
|||
01-04-2019, 08:28 PM
Post: #2
|
|||
|
|||
RE: (11C) Random Move
(01-03-2019 08:55 AM)Gamo Wrote: 1 I wonder what may be the reason for these six lines of code just to generate the value 1010. Why not a simple "EEX 10"? Too easy ?-) The program determines a random number which is 1, 0 or –1. It then does various tests to decide whether R2 is divided by 10, left unchanged or multiplied by 10. Now imagine what happans if instead of all this you simply calculate 101, 100 or 10–1... ;-) Dieter |
|||
01-04-2019, 11:16 PM
Post: #3
|
|||
|
|||
RE: (11C) Random Move
(01-04-2019 08:28 PM)Dieter Wrote:(01-03-2019 08:55 AM)Gamo Wrote: 1 With no context about this question, I'd guess this technique was used in order to have 10 stored in LASTX (for some later use), but definitely not the case here, so probably just Gamo's initial attempt at getting it working before optimizing. --Bob Prosperi |
|||
01-05-2019, 03:43 AM
Post: #4
|
|||
|
|||
RE: (11C) Random Move
(01-04-2019 11:16 PM)rprosperi Wrote: With no context about this question, I'd guess this technique was used in order to have 10 stored in LASTX (for some later use) You could still use: Code: 1 Even if you'd rely on the copy of stack register T there's no need to enter the same number twice. The following steps are enough: Code: 1 Kind regards Thomas |
|||
01-05-2019, 03:58 AM
Post: #5
|
|||
|
|||
RE: (11C) Random Move
(01-05-2019 03:43 AM)Thomas Klemm Wrote:(01-04-2019 11:16 PM)rprosperi Wrote: With no context about this question, I'd guess this technique was used in order to have 10 stored in LASTX (for some later use) Fair enough, I was just guessing why he did that, but these examples show it still could have been easily improved even if that was a goal. Though this code sequence does not really apply, in many programs I've written, I've left non-optimum (either a bit longer or slower) code as-is, if it made the flow or intention more clear. As you and Dieter prove here almost daily, nearly any code sequence can be improved, but sometimes a straightforward program that has been extensively optimized ceases to be recognizable (at least for those of us that don't document these little calculator program explorations). That having been said, please do continue to point out these improvements, as I try to learn a little almost every time. :-) --Bob Prosperi |
|||
01-06-2019, 04:25 AM
Post: #6
|
|||
|
|||
RE: (11C) Random Move
Thanks for all the comment.
The reason I use 10 ENTER 10 Y^X is due to the number display on screen. I'm noticed that when use EEX 10 the result on screen shown exponents but what I want is a full digits show on screen. Gamo |
|||
01-06-2019, 06:55 AM
Post: #7
|
|||
|
|||
RE: (11C) Random Move | |||
01-06-2019, 08:37 AM
(This post was last modified: 01-06-2019 03:31 PM by Dieter.)
Post: #8
|
|||
|
|||
RE: (11C) Random Move
(01-06-2019 04:25 AM)Gamo Wrote: The reason I use 10 ENTER 10 Y^X is due to the number display on screen. ?!? – what exactly is the problem? The way a number is displayed does not depend on the way it is entered or calculated. It does not matter if the value 1010 is generated by EEX 10, 10 ENTER y^x, 10 10x, EEX 5 x² or whatever way you choose. The display is always the same. Assuming FIX 4 mode: Code: 10 [ENTER] 10 [y^x] 1,0000 10 Even if the display really was different: it doesn't matter. The value 1010 is never displayed! The first time a number is displayed in your program is at the end of routine A: RCL 1 RTN (which shows 1.111.111.111). The only other output is shown with the PSE in routine B (which displays 1.111.181.111 etc.). So where do you see a problem? Code: LBL A Dieter |
|||
01-06-2019, 07:51 PM
Post: #9
|
|||
|
|||
RE: (11C) Random Move
(01-05-2019 03:58 AM)rprosperi Wrote: Though this code sequence does not really apply, in many programs I've written, I've left non-optimum (either a bit longer or slower) code as-is, if it made the flow or intention more clear. That's a valid point. Of course it can be fun to shave off the last possible byte. However, I doubt that it is worth the effort if we end up with incomprehensible stack acrobatics. On the other hand, sometimes I'm surprised to see overly complicated programs. In such cases, removing unnecessary code improves the comprehension. Cheers Thomas |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)