HHC 2012 Programming Contests: annotations, comments ...?  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: HHC 2012 Programming Contests: annotations, comments ...? (/thread231890.html) 
HHC 2012 Programming Contests: annotations, comments ...?  Peter Murphy (Livermore)  09242012 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  09252012 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)  09252012 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  09252012 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  09252012 @==============================================================
Edited: 25 Sept 2012, 5:34 p.m.
Re: HHC 2012 Programming Contests: annotations, comments ...?  Gerson W. Barbosa  09252012
Let's consider the example in the drawing above. The source point is (x_{1}, y_{1}) = (2, 3) and the destination point is (x_{2}, y_{2}) = (3, 5). C_{1} and C_{2} in the yaxis are the linear coefficients of the straight lines y = x + C_{1} and y = x + C_{2}, which contain these points. From the drawing, C_{1} = x_{1} + y_{1}; C_{1} = 2 + 3; C_{1} = 5The number of steps marked in orange is n_{1} = C_{2}  C_{1}; n_{1} = 9  5; n_{1} = 4The number of steps marked in blue, from (x_{1}, y_{1}) to C_{1}, is n_{2} = x_{1}; n_{2} = 2The number of steps marked in green, from the xaxis to (x_{2}, y_{2}), is n_{3} = y_{2}; n_{3} = 5The number of the remaining steps, marked in red, is C_{2}1Finally, the total number of steps is n = n_{1} + n_{2} + n_{3} + n_{4}; n = 4 + 2 + 5 + 21; n= 32or, generically, n = C_{2}  C_{1} + x_{1} + y_{2} + (C_{2}^{2}  C_{2}  C_{1}^{2}  C_{1})/2which can be simplified to n = ((x_{2} + y_{2})^{2} + (x_{2} + y_{2})  ((x_{1} + y_{1})^{2} + (x_{1} + y_{1})))/2 + y2  y1
The symetry of the latter allows for this HP 50g 55byte 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  09262012 « 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  09262012 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)  09262012 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  09262012 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  09262012 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  09262012 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)  09262012 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)  09262012 According to the "Command MenuPath 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  10012012 The expression n = ((x_{2} + y_{2})^{2} + (x_{2} + y_{2})  ((x_{1} + y_{1})^{2} + (x_{1} + y_{1})))/2 + y2  y1
above can be simplified on the HP28S (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 13step HP15C program:
001 42 34 f CLEAR REG
Gerson.
Re: HHC 2012 Programming Contests: annotations, comments ...?  Katie Wasserman  10022012 I love recall register arithmetic and nonstandard 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  10022012 It's only a pity that CLEAR SIGMA clears also the HP15C stack. On the HP34C and HP41 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 HP15C and HP42S 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  10022012 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  10022012 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.  10172012 Gerson,
Re: HHC 2012 Programming Contests: annotations, comments ...?  Gerson W. Barbosa  10172012 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.
