HHC 2012 Programming Contests: annotations, comments ...? - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: HHC 2012 Programming Contests: annotations, comments ...? (/thread-231890.html) |
HHC 2012 Programming Contests: annotations, comments ...? - Peter Murphy (Livermore) - 09-24-2012 As a relative newbie to RPL -- and to anything more than simple keystroke RPN -- I would find it very useful to have annotated solutions to the HHC 2012 Programming Contest problems. Equally useful would be discussions of nice insights into the problems and of nice bits of code. All that's easy for me to ask, of course; I'd be most appreciative of any efforts in those directions. And thanks in advance for such.
Peter
Re: HHC 2012 Programming Contests: annotations, comments ...? - David Hayden - 09-25-2012 My solution is commented in this post. Note that Bill Butler has written analyses of several past programming problems in Datafile. I wrote an analysis in Datafile one year too.
Dave
Re: HHC 2012 Programming Contests: annotations, comments ...? - Peter Murphy (Livermore) - 09-25-2012 David, I just read your message as I was headed for bed. I'll follow those links in the morning.
Thanks a lot for your reply. The generosity on view in this Forum is wonderful.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Thomas Klemm - 09-25-2012 Using the definitions below I ended up with the same formula as David Hayden: n = (s+1)*ds/2+dy
Instead of listing my own solution I'm commenting Werner's program as it is an improvement: X Y Z TKind regards Thomas Edited: 25 Sept 2012, 7:17 a.m.
Re: HHC 2012 RPL Programming Contests: annotations, comments ...? - Gilles Carpentier - 09-25-2012 @==============================================================
Edited: 25 Sept 2012, 5:34 p.m.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 09-25-2012
Let's consider the example in the drawing above. The source point is (x1, y1) = (2, 3) and the destination point is (x2, y2) = (3, 5). C1 and C2 in the y-axis are the linear coefficients of the straight lines y = -x + C1 and y = -x + C2, which contain these points. From the drawing, C1 = x1 + y1; C1 = 2 + 3; C1 = 5The number of steps marked in orange is n1 = C2 - C1; n1 = 9 - 5; n1 = 4The number of steps marked in blue, from (x1, y1) to C1, is n2 = x1; n2 = 2The number of steps marked in green, from the x-axis to (x2, y2), is n3 = y2; n3 = 5The number of the remaining steps, marked in red, is C2-1Finally, the total number of steps is n = n1 + n2 + n3 + n4; n = 4 + 2 + 5 + 21; n= 32or, generically, n = C2 - C1 + x1 + y2 + (C22 - C2 - C12 - C1)/2which can be simplified to n = ((x2 + y2)2 + (x2 + y2) - ((x1 + y1)2 + (x1 + y1)))/2 + y2 - y1
The symetry of the latter allows for this HP 50g 55-byte program: PGM1:
Example: 2 ENTER 3 ENTER 4 ENTER 5 PGM1 --> 32 This doesn't mean, however, smaller RPL programs are not possible. Gerson.
Edited: 25 Sept 2012, 9:17 p.m.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gilles Carpentier - 09-26-2012 « ROT DUP2 - 5 ROLLD Well done ! But with the Score= Time * Size,perhaps this could have a best score :
« ROT DUP2 - 5 ROLLD Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 09-26-2012 Quote: Merci. Venu du maître du RPL, c'est vraiment un compliment ! :-)
Quote: Your're right. I had tried that first, 57.5 bytes I think, running time below 50 milliseconds. START NEXT saved 2.5 bytes, but has introduced a small delay. That problem was meant for RPN calculators only, hence the scarce number of RPL solutions. A quest for even smaller code using various formulas and tricks might be interesting however. Cheers,
Gerson.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Neil Hamilton (Ottawa) - 09-26-2012 Probably a silly question but how are you deriving the runtime? Do you encapsulate and call your program with TICKS or something? Possibly something like this:
<< TICKS -> t Just curious.
Thanks...
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gene Wright - 09-26-2012 Put the inputs on the stack, followed by the program name in quotes, then TEVAL and press ENTER.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 09-26-2012 Yes. From the catalog HELP, HP49G,49G+ & 50 g: Evaluates object and It appears TEVAL is available only from the catalog.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gene Wright - 09-26-2012 When I was judging the contest, I just held down the alpha key and pressed TEVAL then let the alpha key go and pressed eval.
Wasn't too tough. If I were doing it for a lot of situations, I would assign it to a key.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Neil Hamilton (Ottawa) - 09-26-2012 Great! Thanks.
It appears that TEVAL is not in my 48SX I have at work. I will try it on my 48G and 50 at home tonight.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Neil Hamilton (Ottawa) - 09-26-2012 According to the "Command Menu-Path Table" from 50 AUR(?) [Appendix I], TEVAL did not arrive until ROM rev 1.05 -- which is presumably the 49G and onwards. So no luck on my 48G either. Oh well. I'll try in my 49G+ (2.15). ...time passes... Tried it on my 49G+ and it seems to return a variable amount: +/- 0.002 s. Not too surprising. It looks like my little UserRPL knockoff does essentially the same as TEVAL (slightly improved from previous stab -- formatted to look similar to TEVAL) so I should be about to do this on 48g/s as well:
<< TICKS -> t Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 10-01-2012 The expression n = ((x2 + y2)2 + (x2 + y2) - ((x1 + y1)2 + (x1 + y1)))/2 + y2 - y1
above can be simplified on the HP-28S (if one is not willing to do it manually) using the EXCO program (page 256 of the Owner's Manual) as follows: '((x2+y2)^2+(x2+y2)-which can be further simplified as '((x2 - x1) + 3*(y2 - y1) + (x2^2 - x1^2) + (y2^2 - y1^2))/2 + (x2*y2 - x1*y1)'This allows for the following 13-step HP-15C program:
001- 42 34 f CLEAR REG
Gerson.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Katie Wasserman - 10-02-2012 I love recall register arithmetic and non-standard use of Sigma+, I've done that too in several programs to shorten (and obfuscate) code. But I don't recall ever using Sigma- for that purpose, nice one!
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 10-02-2012 It's only a pity that CLEAR SIGMA clears also the HP-15C stack. On the HP-34C and HP-41 it does not, but then they lack recall arithmetic. More recent RPN calculators, the WP 34s included, have dedicated statistical registers (with neither storage nor recall arithmetic, of course). So it appears this solution will fit the HP-15C and HP-42S only, better on the latter on which CLSIGMA can be used instead of CLEAR REG, thus preserving all registers but the statistical ones.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Paul Dale - 10-02-2012 Version 2 firmware for the 34S doesn't have separate statistical registers. They occupy the high numbered registers instead. The 34S only got separate (& more accurate) statistical registers once memory partitioning was implemented in version 3.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 10-02-2012 I think I'll stick to Version 3. That would save only one step anyway.
Gerson.
Re: HHC 2012 Programming Contests: annotations, comments ...? - Jeff O. - 10-17-2012 Gerson,
Re: HHC 2012 Programming Contests: annotations, comments ...? - Gerson W. Barbosa - 10-17-2012 Hello Jeff,
Thanks for the compliment! Clearing all registers is a disadvantage, though. It's a pity Clear Stack and Clear Statistics are merged into one single instruction on the Voyagers. Best regards,
Gerson.
|