1089 Magic Trick
|
06-18-2018, 08:45 AM
(This post was last modified: 06-18-2018 09:29 AM by Dieter.)
Post: #2
|
|||
|
|||
RE: 1089 Magic Trick
(06-18-2018 03:56 AM)Gamo Wrote: My program will do any reversed digits and make sure that the top digits is larger than the second digits so that when subtracting the result will not be negative. Yes, the program checks whether R1≤R2 and then it calculates either R1–R2 or R2–R1 to ensure a positive result. But... why don't you simply use ABS(R1–R2)? You could also use X>Y? X<>Y . This makes sure the larger number is in Y and the smaller one in X. (06-18-2018 03:56 AM)Gamo Wrote: The problem is there are 648 legitimate 3-digits numbers with no repeated digits and 136 of them produce 198 rather than 1089 ...while your program reverses the 99 to 99 again so that the result is 198. That's because you simply copied a digit reversal routine from an earlier thread, without adapting it to this special task. The routine stops the reversing process as soon as the remaining digits are all zero. That's what the x≠0? test is for. But in this special case the input and output always have three digits. So while the present routine reverses a "99" correctly into "99" again, we have to reverse "099" into "990". This means that the loop must not stop if the remaining digits are zero, instead the loop has to be executed exactly 4 times (four, not three because of the way it works). I have adjusted the reversal routine accordingly, and it also preserves the Y and Z register now so that no storage register is required for the intermediate results. Code: LBL A 235 [A] => 1089 132 [A] => 1089 012 [A] => 1089 Check the reversal routine: 001 [GSB] 0 => 100 012 [GSB] 0 => 210 123 [GSB] 0 => 321 Edit: if you want to see the intermediate results, insert PSE commands after each of the two GSB 0 and another one after the ABS. 235 [A] => "532" ... "297" ... "792" ... 1089 Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
1089 Magic Trick - Gamo - 06-18-2018, 03:56 AM
RE: 1089 Magic Trick - Dieter - 06-18-2018 08:45 AM
RE: 1089 Magic Trick - Gamo - 06-18-2018, 09:46 AM
RE: 1089 Magic Trick - Dieter - 06-18-2018, 09:50 AM
RE: 1089 Magic Trick - grsbanks - 06-18-2018, 03:17 PM
|
User(s) browsing this thread: 1 Guest(s)