HP Forums
HHC 2017 RPN Programming contest information and results thread - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HHC 2017 RPN Programming contest information and results thread (/thread-9084.html)

Pages: 1 2 3


HHC 2017 RPN Programming contest information and results thread - Gene - 09-15-2017 11:00 PM

Hello all. The PDF of the programming contest is attached below.

Please work on this problem and do not post RESULTS of your work until after 6pm Nashville CDT on Sunday.

Questions here are fine, but please try not to give away how you are approaching the problem with your question. Ask carefully.

I hope you enjoy the problem. Happy programming!


RE: HHC 2017 RPN Programming contest information and results thread - Paul Dale - 09-15-2017 11:15 PM

Interesting. I like the happy numbers.


Pauli


RE: HHC 2017 RPN Programming contest information and results thread - brouhaha - 09-16-2017 09:27 AM

Stayed up too late prior to start of conference working on the contests. My RPN prog is currently 70 bytes, needs no registers (just stack and alpha). I will need to ask Gene to clarify a question about the output formt.


RE: HHC 2017 RPN Programming contest information and results thread - Didier Lachieze - 09-16-2017 09:48 AM

My current RPN program is 65 bytes including 1 register (7 bytes).

EDIT: down to 62 bytes after a few changes.
EDIT 2: I forget rule 6 and need to add 9 bytes for LBL HAPPY... So with a few optimizations it's now at 70 bytes including the END instruction.
EDIT 3: well, after following all the rules (I hope so) I'm at 75 bytes, with a program starting with LBL HAPPY and restoring all defaults settings before ending with a regular END.


RE: HHC 2017 RPN Programming contest information and results thread - Dave Britten - 09-16-2017 04:08 PM

76 bytes (according to RCLPTA) and no storage registers.

If we don't use any storage registers, is including SIZE 00 mandatory, or can SIZE be omitted entirely?


RE: HHC 2017 RPN Programming contest information and results thread - brouhaha - 09-16-2017 04:54 PM

Found a bug in my program. Was afraid it would get bigger, but with fix and some more optimization, I'm down to 68 bytes and 0 registers. At the moment I don't have any great ideas for shaving off more bytes.

CORRECTION! Gene just told me that he reversed a decision I wrote about here previously. Rule 11 of the RPN contest DOES apply. "Your program must stop with the default settings in place." Unfortunately that does increase the size of my program again.

Also, Gene said that the program output has to match the example output EXACTLY. If the program output looks different than the examples, it will be considered to FAIL. For example, he said that an output of "HAPPY 4.0000" is not accepted.


RE: HHC 2017 RPN Programming contest information and results thread - Gene - 09-16-2017 06:22 PM

yes, Eric is correct. My apologies.

Default settings should be restored when a program ends. If Flag 0 is clear by default and you need to set flag 0 for some reason, when the program halts, be sure that you have cleared flag 0 again.

Also, as Eric says, if the sample output shows HAPPY 4, then do not show Happy 4. or Happy 4.00 etc.

I hope everyone is enjoying the challenge!


RE: HHC 2017 RPN Programming contest information and results thread - Didier Lachieze - 09-16-2017 06:29 PM

Thanks for the challenge Gene! I wish I were with all of you at the HHC.
One point in the contest is not clear for me, if the program ends with RTN do we have to count any END that may be after it ? Or can we rely on the .END. at the end of program memory without including it in the byte-count ?


RE: HHC 2017 RPN Programming contest information and results thread - Gene - 09-16-2017 06:35 PM

End a program with a 3-byte regular END.


RE: HHC 2017 RPN Programming contest information and results thread - brouhaha - 09-16-2017 08:37 PM

My prog is at 72 bytes w/ initial label, restoration to default state, and END. I don't think I'll stare at it any longer, as all my recent ideas for shortening it have either left the byte count unchanged, or actually increased. Maybe I can find some improvements to my RPL contest entry instead.


RE: HHC 2017 RPN Programming contest information and results thread - Gene - 09-16-2017 10:16 PM

EDITED EDITED...

Keep the LBL HAPPY for the start of the program. MY apologies. Too many things going on doing this and the live conference. Sorry all!



ALSO a clarification on the SIZE XYZ aspect.

That is meant to mean that if you use a register, it will add 7 bytes to your byte count. If you store values into 3 memories, that's 3x7 or 21 bytes to your count.

A byte count cost of 7 bytes/register used will be assessed whether you have to change the default SIZE setting or not.


RE: HHC 2017 RPN Programming contest information and results thread - Gerson W. Barbosa - 09-17-2017 03:50 PM

Late to the party and still no happiness.
I tried it on the HP-42S first, avoiding its specific instructions. 66+ 7 bytes (1 register) on the 41CX. Too bad it won't work as expected without the Advantage ROM. I didn't know AIP wasn't a standard 41CX instruction.
Looking forward to all valid solutions.

Gerson.


RE: HHC 2017 RPN Programming contest information and results thread - Dave Britten - 09-17-2017 04:09 PM

I'm at 70 bytes, no storage registers, and I don't think I'll be able to squeeze it down any more than that.


RE: HHC 2017 RPN Programming contest information and results thread - Werner - 09-17-2017 05:38 PM

Edited: 71 bytes including END, no registers used.
Werner


RE: HHC 2017 RPN Programming contest information and results thread - DanM - 09-17-2017 10:42 PM

OK I will break the ice. Here's my entry from Nashville. See attachment, I don't want to put it into the message itself.

It's not the highest byte count and not the lowest byte count. I think it works, but would be first to say it is far from both optimum and elegant.

82 bytes, no registers.

I would like to see other solutions.


RE: HHC 2017 RPN Programming contest information and results thread - Gerson W. Barbosa - 09-17-2017 11:51 PM

74 bytes, stack-only... on the 42S. Probably more on the 41CX and surely even more if done by the rules (without AIP).
Interesting programming exercise as always. Thanks!

-----------

Edited to include 42S code. Size optimization not tried yet.

Code:

00 { 74-Byte Prgm }
01▸LBL "HAPPY"
02 CLA
03 0
04 STO ST Z
05 STO ST T
06▸LBL 00
07 CLX
08 R↓
09▸LBL 01
10 10
11 %
12 IP
13 X<>Y
14 X<> ST L
15 FP
16 STO× ST X
17 STO+ ST T
18 SIGN
19 ×
20 X≠0?
21 GTO 01
22 X<> ST Z
23 2
24 10↑X
25 ×
26 1
27 STO+ ST Z
28 X=Y?
29 GTO 03
30 CLX
31 4
32 X≠Y?
33 GTO 00
34 "UN"
35▸LBL 03
36 ├"HAPPY "
37 RCL ST Z
38 AIP
39 AVIEW
40 END



RE: HHC 2017 RPN Programming contest information and results thread - Dave Britten - 09-18-2017 12:51 AM

Well, I got it to 70 bytes, but we found some edge cases it choked on (0 cycles). Changing the position of one instruction fixes it, without affecting the size. Here's the fixed version for anybody that wants to vastly outdo me. Big Grin

Code:
LBL "HAPPY"
CF 29
FIX 0
0
X<>Y
ENTER^
CLA
LBL 00
RDN
4
X=Y?
GTO 4
RDN
1
X=Y?
GTO 03
RDN
ARCL ST X
CLX
ISG ST Y
LBL 01
ATOX
X=0?
GTO 00
48
-
X^2
+
GTO 01
LBL 04
"UN"
LBL 03
|-"HAPPY " (Note the space after the Y)
ARCL ST Z
SF 29
FIX 4
AVIEW
END



RE: HHC 2017 RPN Programming contest information and results thread - Didier Lachieze - 09-18-2017 03:05 AM

Aha.... I didn't think using ATOX for the digit extraction, shame on me.

So here is my program in 75 bytes (68 + 7 for register 00). The good thing is that it works on the 41C without any module.
Code:
Step Bytes Instruction 
 1    9    LBL "HAPPY"
 2    1    CLA
 3    2    FIX 0
 4    2    CF 29
 5    1    0
 6    1    STO 00
 7    1    LBL 01
 8    1    CLx
 9    1    x<>y
10    2    ISG 00
11    1    LBL 02
12    2    STO Z
13    2    10
14    1    MOD
15    1    x^2
16    1    +
17    1    X<>Y
18    2    10
19    1    /
20    1    INT 
21    1    x#0?
22    2    GTO 02
23    1    SIGN
24    1    x=y?
25    2    GTO 03
26    1    3
27    1    +
28    1    x#y?
29    2    GTO 01
30    3    "UN"
31    1    LBL 03
32    8    "|-HAPPY "
33    2    ARCL 00
34    1    AVIEW
35    2    SF 29
36    2    FIX 4
37    3    END
     68

And here is a solution in 69 bytes using ATOX:
Code:
Step Bytes Instruction 
 1    9    LBL "HAPPY"
 2    2    FIX 0
 3    2    CF 29
 4    1    0
 5    2    STO Z
 6    1    LBL 01
 7    1    CLx
 8    1    x<>y
 9    1    CLA
10    2    ARCL X
11    1    RDN
12    2    48
13    2    ISG Z
14    1    LBL 02
15    2    48
16    1    -
17    1    x^2
18    1    +
19    2    ATOX
20    1    x#0?
21    2    GTO 02
22    1    SIGN
23    1    x=y?
24    2    GTO 03
25    1    3
26    1    +
27    1    x#y?
28    2    GTO 01
29    3    "UN"
30    1    LBL 03
31    8    "|-HAPPY "
32    2    ARCL Z
33    1    AVIEW
34    2    SF 29
35    2    FIX 4
36    3    END
     69



RE: HHC 2017 RPN Programming contest information and results thread - David Hayden - 09-18-2017 04:27 AM

Here's my entry. 75 bytes (according to Free42) using 41C instructions and no storage registers.
Code:
01 LBL "HAPPY"
02 CLA
03 FIX 00
04 CF 29        @ to get "HAPPY 2" instead of "HAPPY 2.0000"
05 IP           @ Store in LastX
06 CLST
07 LASTX        @ XYZT = num,,0,0,0

08 LBL 01       @ X,Y,Z = number, (sum of digits (SOD)/100), loopCounter
09 10
10 /
11 ENTER
12 FP           @ digit/10
13 X^2          @ digit/100
14 STO+ ST Z    @ sum of digits/100
15 SQRT         @ digit/10
16 -            @ new number
17 X=0?         @ if X=0, increment loop count, go to step 20
18 ISG ST Z     @ if X≠0, GTO 01
19 GTO 01

20 R↓           @ SOD/100, loopCount, ? ?
21 100
22 ×            @ SOD loopCount ? ?
23 1
24 X=Y?
25 GTO 02       @ It's happy
26 3
27 +
28 X=Y?
29 GTO 03       @ It's unhappy
30 CLX          @ Restore stack to 
31 X<>Y?        @ Stk: SOD (aka new number), 0 (new SOD/100) loopCount
32 GTO 01       @ Back to loop

33 LBL 03
34 "UN"
35 LBL 02
36 Ⱶ"HAPPY "    @ Append "HAPPY " to empty string (see line 2) or "UN"
37 ARCL ST Z    @ loop count
38 AVIEW
39 SF 29        @ restore defaults
40 FIX 04
41 .END.



RE: HHC 2017 RPN Programming contest information and results thread - Werner - 09-18-2017 05:36 AM

71 bytes, no regs

Code:
01>LBL"HAPPY"
02 CLA
03 0
04 X<>Y
05 ENTER
06>LBL 02
07 CLX
08 X<>Y
09>LBL 03
10 10
11 X<>Y
12 %
13 FRC
14 ST* Y
15 X<> L
16 INT
17 RDN
18 X^2
19 +
20 R^
21 X>0?
22 GTO 03
23 SIGN
24 ST+ Z
25 X=Y?
26 GTO 01
27 CLX
28 4
29 X!=Y?
30 GTO 02
31 "UN"
32>LBL 01
33 +"HAPPY "
34 CF 29
35 FIX 0
36 ARCL Z
37 FIX 4
38 SF 29
39 AVIEW
40 END

Cheers, Werner