HHC 2019 will be in Reno, Nevada, Sept 21-22
|
09-24-2019, 07:06 PM
Post: #41
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22 | |||
09-24-2019, 07:54 PM
Post: #42
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
Hi,
For what it is worth, Roger Hill's RPL solution ran in less than 5 seconds, if I remember correctly. Hopefully, the winning ones in each machine category can be posted in the near future. Thanks, Jake |
|||
09-25-2019, 01:04 AM
Post: #43
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-24-2019 07:06 PM)Eric Rechlin Wrote: But you can only submit entries if you are present, and you weren't present, so I don't understand why it matters to you. I'm embarrassed to say I wasn't aware of that rule. I apologize for all the fuss. Brian Walsh (6951) [41] <1> |
|||
09-25-2019, 01:53 AM
Post: #44
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-23-2019 03:08 AM)Wes Loewer Wrote: Here are my smallest and my fastest 50g entries: Based on Claudio’s idea: Code:
96 bytes, 214.7 seconds. Your smallest one can get even smaller by simply replacing 100 with 2 ALOG (down to 89.5 bytes). My very first program would take one minute to run, probably because of cubes being computed as 3 y^3, instead of DUP SQ. Now 21.7 seconds and incidentally 154 bytes long: Code:
|
|||
09-25-2019, 07:26 PM
Post: #45
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-24-2019 02:22 AM)dramsey Wrote: Regarding this year's programming contest: You also required that the four results be on the stack at the end, so after four were found it would be natural to stop. Pretending that I did not know there would be only four results, and therefore not knowing that they would fit on the stack so I had to come up with my own way to present the results, I came up with the program below, for 42S/DM42/Free42. It simply seqentially checks all 3 digit numbers, then stops and shows each successful result as it is found. The user must press R/S to continue, with "999" in the X register indicating all numbers have been checked and all successful results displayed. Code:
(This program used the core of my program for Gene's "Happy Number" challenge of a few years ago which summed digits squared - so I had the code handy and it was easy to modify that to sum digits cubed. Also, yes, it could stop at 963, but that's not much of an optimization so I just go all the way to 999.) Dave - My mind is going - I can feel it. |
|||
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" |
|||
09-27-2019, 04:48 PM
Post: #47
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-26-2019 05:33 PM)David Hayden Wrote: Here is my entry, which won the "Modern RPN" prize. I keyed in David's HHC programming solution into my DM42. OMG! It's blazing fast! Not even using USB power. It takes about +1 second to find all four (4) solutions. I wondered if David somehow hid the four solutions in the code somewhere. LOL. (just kidding). So I put in loop counters into each of his three loops X, Y & Z. The X-loop took 9 iterations. The Y-loop took 90 iterations and the Z-loop took 538 iterations. All totaled, the program looped 435,780 times in about one second. Viva DM42! I'm certain someone could figure out a more accurate execution time by counting bytes and estimating the execution time based on processor speed. But don't blink....it's fast. Nice solution, Dave! And zippy too! |
|||
09-27-2019, 09:31 PM
Post: #48
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-27-2019 04:48 PM)jjohnson873 Wrote: I keyed in David's HHC programming solution into my DM42. OMG! It's blazing fast!Thanks Jim! (09-27-2019 04:48 PM)jjohnson873 Wrote: So I put in loop counters into each of his three loops X, Y & Z. The X-loop took 9 iterations. The Y-loop took 90 iterations and the Z-loop took 538 iterations. All totaled, the program looped 435,780 times in about one second. Viva DM42!My Prime version indicated 440 iterations in the Z loop, but maybe that was an earlier version. I think you've computed the total number of loops incorrectly. Since you measured the actual number of times in each loop, you should add them, not multiply. I'm sure that someone will post a faster/smaller RPN solution, if they haven't already. |
|||
09-27-2019, 09:59 PM
Post: #49
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-27-2019 09:31 PM)David Hayden Wrote:So these loops aren't nested inside of each other? I made an assumption they were nested, but should have checked the algorithm. It's still FAST! Thanks, Dave!(09-27-2019 04:48 PM)jjohnson873 Wrote: I keyed in David's HHC programming solution into my DM42. OMG! It's blazing fast!Thanks Jim! |
|||
09-27-2019, 11:07 PM
Post: #50
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-23-2019 01:54 PM)Claudio L. Wrote: My take, nothing clever here, just plain brute force. OK, now it's time to get a bit clever. Below is a version of Wes's brute force, but this time it precomputes all multiplications and powers and stores them in lists. This brings down execution time down to 49 ms (from 68 ms), 27% faster at the expense of some memory. Code:
And talking about clever... here comes David. The code below is identical except it does David's early exit trick, bringing down total execution time now to 35 ms. Code:
|
|||
09-28-2019, 12:44 AM
Post: #51
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-23-2019 01:54 PM)Claudio L. Wrote: My take, nothing clever here, just plain brute force. I had solved this previously, I found this code already in my calc I guess from some old challenge?. Hello Claudio....was this written and run on an HP Prime or a different calculator? I was curious about how you arrived at the very accurate msec. timing. |
|||
09-28-2019, 01:26 AM
(This post was last modified: 10-11-2019 01:06 AM by Albert Chan.)
Post: #52
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
HP71B version, with a running sum of number less cube of its digits.
If the total is zero, we found an Armstrong number. Slight optimization on the inner loop. Instead of running from 0 to 9, do 2 to 9 If Armstrong number N last digit is 0, N+1 must also be an Armstrong number. Code: 10 DESTROY ALL @ DIM C(10) @ FOR I=1 TO 9 @ C(I)=I^3-I @ NEXT I Note: discovered a BASIC quirk FOR NEXT loops variable ends with first value that failed the loop. >FOR K=1 TO 100 STEP 7 @ NEXT K >K 106 So, above code Z loop can also do 2 to 8, and still run correctly. Update: Y loop optimized with parity test, cutting search space in half. see https://www.hpmuseum.org/forum/thread-13791.html |
|||
09-28-2019, 04:37 PM
Post: #53
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-26-2019 05:33 PM)David Hayden Wrote: ... 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). My version may have been “only” 35 steps, but did not put the results on the stack as per the rules. If I add steps to do so brought, it is now 42 steps, and it takes approximately 3.5 to 4 seconds to run on my DM42. The extra steps for your more elegant and (verified) much faster program are well worth it. Dave - My mind is going - I can feel it. |
|||
09-28-2019, 04:38 PM
Post: #54
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-27-2019 09:59 PM)jjohnson873 Wrote: So these loops aren't nested inside of each other? I made an assumption they were nested, but should have checked the algorithm. It's still FAST! Thanks, Dave!Yes they are nested, but if you added a counter inside the Z loop then you counted the total number of loops in X, Y, and Z. The Z loop definitely doesn't run half a million times to check just 900 numbers |
|||
09-28-2019, 04:45 PM
Post: #55
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
I think this can be used to time the program:
LBL 01 TIME STO 24 XEQ "CUBES" ; or whatever program you're timing TIME RCL 24 HMS- END On my DM42, my program takes 1.02s. On a 41C w/ quad memory module, 5 minutes, 7 seconds. |
|||
09-29-2019, 04:08 PM
Post: #56
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22 | |||
09-30-2019, 03:15 AM
(This post was last modified: 09-30-2019 03:16 AM by Craig Bladow.)
Post: #57
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-28-2019 04:45 PM)David Hayden Wrote: I think this can be used to time the program: I used Dave's timing program to time my entry to the programming contest at HHC 2019. It runs in 1.4 seconds on a DM42 running on battery. The program reduces the search space to 8*8*8 by not evaluating some combinations that would sum to greater than 999. Code:
Try CC41! |
|||
09-30-2019, 03:56 AM
Post: #58
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
Code:
Cheers all |
|||
09-30-2019, 05:13 AM
Post: #59
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
Just by looking at your code I noticed some questionable steps
(09-30-2019 03:15 AM)Craig Bladow Wrote: I used Dave's timing program to time my entry to the programming contest at HHC 2019. Cheers, |
|||
09-30-2019, 04:15 PM
Post: #60
|
|||
|
|||
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
One final RPL version: no loops!
This one is also newRPL specific (sorry, it's what I use, I don't mean to leave anybody out): Code:
Loopless is not faster, mainly because of the overhead of creating the lists, but worth a look as a curiosity. This one runs in 113ms. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 9 Guest(s)