Post Reply 
HHC 2017 RPN Programming contest information and results thread
09-18-2017, 06:00 AM
Post: #21
RE: HHC 2017 RPN Programming contest information and results thread
Dave: if you replace

RDN
1

by

SIGN

you're down to 69. Congrats!

Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-18-2017, 07:51 AM
Post: #22
RE: HHC 2017 RPN Programming contest information and results thread
I've been able to get it down to 68 bytes, Dave's idea

Code:
>LBL"HAPPY"
 CLA
 CF 29
 FIX 0
 0
 STO Z
>LBL 02
 CLX
 4
 X=Y?
 GTO 04
 SIGN
 X=Y?
 GTO 01
 ARCL Y
 MOD
 ISG Y
>LBL 03
 ATOX
 X=0?
 GTO 02
 48
 -
 X^2
 +
 GTO 03
>LBL 04
 "UN"
>LBL 01
 +"HAPPY "
 ARCL Z
 SF 29
 FIX 4
 AVIEW
 END

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-18-2017, 08:23 AM
Post: #23
RE: HHC 2017 RPN Programming contest information and results thread
Just wondering if a CLSTK at the end is shorter than the '0' at step 5?
Default state at the start means zeros on the stack but to be rerunnable these have to be restored.

Pauli
Find all posts by this user
Quote this message in a reply
09-18-2017, 09:03 AM
Post: #24
RE: HHC 2017 RPN Programming contest information and results thread
No, 0 and CLST are both 1 byte on a 41.
Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-18-2017, 11:02 AM (This post was last modified: 09-18-2017 11:03 AM by Didier Lachieze.)
Post: #25
RE: HHC 2017 RPN Programming contest information and results thread
(09-18-2017 07:51 AM)Werner Wrote:  I've been able to get it down to 68 bytes, Dave's idea

Excellent! but there are too much labels. We can save one byte by removing LBL 01 , going down to 67 bytes:
Code:
Step  Bytes    Instruction 
 1      9     >LBL"HAPPY"
 2      2      CLA
 3      2      CF 29
 4      1      FIX 0
 5      1      0
 6      2      STO Z
 7      1     >LBL 02
 8      1      CLX
 9      1      4
10      1      X#Y?
11      1      SIGN
12      1      X=Y?
13      2      GTO 04
14      2      ARCL Y
15      1      MOD
16      2      ISG Y
17      1     >LBL 03
18      2      ATOX
19      1      X=0?
20      2      GTO 02
21      2      48
22      1      -
23      1      X^2
24      1      +
25      2      GTO 03
26      1     >LBL 04
27      2      DSE X
28      3      "UN"
29      8      "|-HAPPY "
30      2      ARCL Z
31      2      SF 29
32      2      FIX 4
33      1      AVIEW
34      3      END
       67
Find all posts by this user
Quote this message in a reply
09-18-2017, 11:26 AM
Post: #26
RE: HHC 2017 RPN Programming contest information and results thread
You Shall Not Pass!

66 bytes

Code:
>LBL"HAPPY"
 CLA
 CF 29
 FIX 0
 0
 STO Z
>LBL 02
 CLX
 4
 X!=Y?
 SIGN
 X=Y?
 GTO IND X
 ARCL Y
 MOD
 ISG Y
>LBL 03
 ATOX
 X=0?
 GTO 02
 48
 -
 X^2
 +
 GTO 03
>LBL 04
 "UN"
>LBL 01
 +"HAPPY "
 ARCL Z
 SF 29
 FIX 4
 AVIEW
 END

Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-18-2017, 11:39 AM
Post: #27
RE: HHC 2017 RPN Programming contest information and results thread
Ah, I KNEW there had to be a way to improve the 4/1 tests somehow. Didn't think to use SIGN and indirect GTO. Very nice.
Visit this user's website Find all posts by this user
Quote this message in a reply
09-18-2017, 08:04 PM
Post: #28
RE: HHC 2017 RPN Programming contest information and results thread
Some of the below is repeated in the post for the RPL programming contest...

--------------------------------------------------------------------------------------------
The way the contests work at a real HHC gathering goes something like this.

1) We announce that program submissions (a physical machine with the program in it already AND a printed/hand written listing of the program AND the author's name on the machine and listing) are due to the judge at say Noon.

2) Noon happens to be when we break for lunch.

3) So as we break for lunch, those entering the contest are fighting their way to the judge who has to be careful to keep the machines safe (I dropped a 41C two years ago and broke it - ugh - didn't enjoy getting that fixed).

4) The judge tries to go get some lunch and then runs the inputs to the RPL and RPN contests on the machines and tries to record results / score them.

5) This is often a slow process since people want to be friendly and are curious. Personally, I don't like to hide, but I probably should.

6) The contest results are usually determined in an hour or so and then announced around 3pm. The results are kept secret until then.

7) Winner of each contest gets to pick a prize from the prize table AFTER the Best Speaker picks one but before all the other attendees will pick one.

8) The judge then starts trying to think of a contest for next year!

--------------------------------------------------------------------------------------------
Here are the numbers I used as test inputs.


Number 1: 123,456,789
Result: UNHAPPY 13

Number 2: 987,654,321
Result: UNHAPPY 13

Number 3: 555,555,555
Result: UNHAPPY 12

Number 4: 20
Result: UNHAPPY 1

Number 5: 989
Result: HAPPY 6

Number 6: 13
Result: HAPPY 2

Number 7: 15999
Result: UNHAPPY 16 (Note: 16 is the highest number of cycles required for a 10 digit or less number to process. Thanks, Eric Smith for finding this!)

Number 8: 100
Result: HAPPY 1

Number 9: 8002
Result: HAPPY 3

Number 10: 1
Result: HAPPY 1
Find all posts by this user
Quote this message in a reply
09-18-2017, 09:23 PM (This post was last modified: 09-19-2017 04:34 PM by Don Shepherd.)
Post: #29
RE: HHC 2017 RPN Programming contest information and results thread
Never having used a 41, I wanted to implement the problem using the 17bii solver. Here is the equation:
Code:
HAPPY:HAP+CYC+
ANS=SIGMA(I:1:100:1:
L(N:SIGMA(J:0:LOG(NUM):1:
SQ(MOD(IDIV(NUM:10^J):10))))
+L(NUM:G(N))+
IF(NUM=1 OR NUM=4:L(HAP:NUM)+L(CYC:I)/0:0))

This is not a normal solver equation, it takes advantage of the fact you can exit a loop by inducing an error in the calculation (divide by 0 works well) after saving whatever values you want in variables that you can then RCL. So, to run this, enter your desired number to test and press NUM. Then press ANS (solve for ANS). After a few seconds it will beep and display SOLUTION NOT FOUND. Just RCL HAP (4=unhappy, 1=happy) and RCL CYC for the number of cycles.
Find all posts by this user
Quote this message in a reply
09-18-2017, 10:26 PM (This post was last modified: 09-18-2017 11:07 PM by John Keith.)
Post: #30
RE: HHC 2017 RPN Programming contest information and results thread
OK then, here's my (irrelevant) RPL version using DavidM's ListExt library:

Code:
\<< 0 SWAP DO I\->NL SQ LSUM SWAP 1 + SWAP
           UNTIL { 1 4 } OVER POS
           END "HAPPY"
        IF SWAP 4 SAME
        THEN "UN" SWAP +
        END \->TAG
\>>
Find all posts by this user
Quote this message in a reply
09-18-2017, 10:36 PM
Post: #31
RE: HHC 2017 RPN Programming contest information and results thread
(09-18-2017 11:02 AM)Didier Lachieze Wrote:  
Code:
Step  Bytes    Instruction 
 1      9     >LBL"HAPPY"
 2      2      CLA

Why should "CLA" require 2 bytes?

Dieter
Find all posts by this user
Quote this message in a reply
09-19-2017, 04:01 AM
Post: #32
RE: HHC 2017 RPN Programming contest information and results thread
Good catch, of course CLA requires only 1 byte instead of 2 and on step 4 FIX 0 requires 2 bytes and not 1. It seems I swapped the byte count for these two instructions, but the total count is right.

I can't find any further optimization of Werner's last code. The GTO IND is brilliant !
Find all posts by this user
Quote this message in a reply
09-19-2017, 05:57 AM
Post: #33
RE: HHC 2017 RPN Programming contest information and results thread
Well, I missed all big improvements (ATOX, the 1/4 combined test), all I did was find two tricks ;-)

Now, what should 1 HAPPY return? "HAPPY 1" or "HAPPY 0"? I vote for the latter.
It's logical that 1 HAPPY is "HAPPY 0" and 10 HAPPY is "HAPPY 1".

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-19-2017, 09:53 AM
Post: #34
RE: HHC 2017 RPN Programming contest information and results thread
Here is my version. It uses synthetic programming. It restores the flags and settings to its previous state and uses register 'a' as counter for the (un-)happy steps.

71 Bytes, no regs.

Regards Bernd

Code:

BYTES   Command
  9     LBL "HAPPY"
  1     LBL 11 
  1     ENTER^
  2     ST- Y       ( prepare Y as summation register)
  1     LBL 12
  2     RCL X
  2     10
  2     ST/ Z
  1     MOD
  1     X^2
  2     ST+ Z       ( calculate sqr sum in Z)
  1     RDN
  1     INT
  1     X#0?
  2     GTO 12
  2     ISG a
  1     ""          ( byte 0xF0 )
  1     RDN
  1     4
  1     X=Y?
  2     GTO 13
  1     SIGN
  1     X<>Y
  1     X#Y?
  2     GTO 11
  1     CLX
  1     LBL 13
  1     CLA
  1     X#0?
  3     "UN"
  8     +"HAPPY "
  2     RCL d
  2     FIX 0
  2     CF 29
  2     ARCL a
  2     STO d
  1     AVIEW
  3     END
--
71 bytes total
Find all posts by this user
Quote this message in a reply
09-19-2017, 12:14 PM
Post: #35
RE: HHC 2017 RPN Programming contest information and results thread
(09-19-2017 05:57 AM)Werner Wrote:  Well, I missed all big improvements (ATOX, the 1/4 combined test), all I did was find two tricks ;-)

Now, what should 1 HAPPY return? "HAPPY 1" or "HAPPY 0"? I vote for the latter.
It's logical that 1 HAPPY is "HAPPY 0" and 10 HAPPY is "HAPPY 1".

Cheers, Werner

Hello all! The powers of the on-site judge are nearly all-inclusive.

Per the rules I wrote :-) which say this:

"Start with a number and replace it with the sum of the squares of each of its digits. Compare the computed sum of these squares to the rules below. Repeat the process with the previous result as the next input."

1 should return HAPPY 1.

Start with a number - in this case 1 is entered.

Then replace it with the sum of the squares of each of its digits. Ok, still 1.

THEN compare the computed sum to the rules below.

At this point, one cycle has occurred so when 1 is evaluated, the cycle count should be 1. Same score as 10 or 100 etc. of course.

:-)
Find all posts by this user
Quote this message in a reply
09-19-2017, 01:05 PM (This post was last modified: 09-19-2017 02:23 PM by Werner.)
Post: #36
RE: HHC 2017 RPN Programming contest information and results thread
I bow to the judge..
[Edited] Still 66 bytes

Code:
>LBL"HAPPY"
 CLA
 CF 29
 FIX 0
 0
 X<>Y
 ENTER
>LBL 02
 ARCL Y
 MOD
 ISG Y
>LBL 03
 ATOX
 X=0?
 GTO 00
 48
 -
 X^2
 +
 GTO 03
>LBL 00
 CLX
 4
 X=Y?
 "UN"
 X!=Y?
 SIGN
 X!=Y?
 GTO 02
 +"HAPPY "
 ARCL Z
 SF 29
 FIX 4
 AVIEW
 END

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
09-19-2017, 03:05 PM (This post was last modified: 09-19-2017 03:06 PM by DanM.)
Post: #37
RE: HHC 2017 RPN Programming contest information and results thread
(09-19-2017 01:05 PM)Werner Wrote:  I bow to the judge..

Wow, that is slick and impressive. Everything that my program isn't. :-)

For the conference, my notes indicate that Gene said 10 entries for the RPN contest and only 5 for the RPL. I find that ratio interesting.
Find all posts by this user
Quote this message in a reply
09-19-2017, 03:18 PM
Post: #38
RE: HHC 2017 RPN Programming contest information and results thread
(09-19-2017 01:05 PM)Werner Wrote:  I bow to the judge..
[Edited] Still 66 bytes

Gene: :-) Don't bow to me! I try not to let those Judging powers go to my head. Honest! lol.
Find all posts by this user
Quote this message in a reply
09-19-2017, 09:02 PM
Post: #39
RE: HHC 2017 RPN Programming contest information and results thread
Here is another 66 byte version that uses Werner's clever trick of 4/1 check. It works on a HP 41C, but uses synthetic commands.

Regards
Bernd

Code:
LBL "HAPPY"
ENTER^
CLA
LBL 11 
CLX
X<>Y
LBL 12
RCL X
10
ST/ Z
MOD
X^2
ST+ Z       ( calculate sqr sum in Z)
RDN
INT
X#0?
GTO 12
ISG a
""          ( byte 0xF0 )
RDN
4
X=Y?
"UN"
X!=Y?
SIGN
X!=Y?
GTO 11
+"HAPPY "
RCL d
FIX 0
CF 29
ARCL a
STO d
AVIEW
END
Find all posts by this user
Quote this message in a reply
09-19-2017, 09:05 PM
Post: #40
RE: HHC 2017 RPN Programming contest information and results thread
(09-19-2017 03:05 PM)DanM Wrote:  For the conference, my notes indicate that Gene said 10 entries for the RPN contest and only 5 for the RPL. I find that ratio interesting.
Those are high numbers for both contests if my memory serves. There are usually more entries for the RPN contest than the RPL one. IN 2016 there were only 4 RPL entries.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)