HHC 2019 will be in Reno, Nevada, Sept 21-22
|
09-26-2019, 05:33 PM
Post: #46
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
Here is my entry, which won the "Modern RPN" prize.
Rather than going through the numbers 100-999 and extracting digits, this goes through the digits and constructs the number. I figured that this would be faster (unverified), but I see from other posts that it results in much larger code (63 steps with the label and END vs. mid-high 30's). Let's call the digits in the number X,Y,Z. So when considering the number 123, X=1, Y=2 and Z=3. The program loops through possible values of X, then Y, then Z. Along the way it computes the partial sums of cubes: S1 = X^3 S2 = X^3+Y^3 S3 = X^3+Y^3+Z^3 and also stores the partial values of the number: N1 = X00 N2 = XY0 N3 = XYZ all of this is to minimize the computation needed in the innermost loop. The program breaks out of the "Z" loop if it determines that the partial sum-of-cubes is larger than any possible value that would be considered in the loop. This cuts the number of iterations in the Z loop to 440. A similar test in the Y loop could avoid some iterations of Z completely but I decided that one pass through the Z loops was worth saving the space and time of the duplicate check. In pseudocode-Prime code, the program is: Code: // Pre-compute 0^3..9^3 Registers (in the end I didn't need some of these) R0..R9 0^3 - 9^3 R10..R11 Partial sums S1..S3 R13..R15 Partial numbers N1..N3 R16..R18 Digits X, Y, and Z R19 Index to store results R20..R23 Results Labels: L02..L04 Top of X, Y, and Z loops L05 Bottom of Y loop L06 Bottom of Z loop Code: 01 LBL "CUBES" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 25 Guest(s)