Post Reply 
HHC 2017 RPN Programming contest information and results thread
09-18-2017, 04:27 AM
Post: #19
RE: HHC 2017 RPN Programming contest information and results thread
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


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



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