Post Reply 
2023 RPN HHC Programming Contest
10-09-2023, 05:27 AM
Post: #41
RE: 2023 RPN HHC Programming Contest
Hi all,

I had a little different approach for my first attempt:
Code:
 01 LBL "HHC"
 02 10^X        1
 03 ENTER^      1       1
 04 10^X        10      1
 05 ST+ Y       10      11
 06 PI          3.14    10      11
 07 INT         3       10      11
 08 *           30      11
 09 STO Z       30      11      30
 10 +           41      30
 11 ST+ Y       41      71
 12 END

That ended up to 23 bytes all together, but also relies on that X == 0 as input.

My second attempt was then instead:

Code:
 01 LBL "HHC"
 02 PI          3.14
 03 1/X         0.31
 04 ACOS        71.4
 05 INT         71
 06 STO Y       71      71
 07 PI          3.14    71      71
 08 SQRT        1.77    71      71
 09 /           40.05   71
 10 INT         40      71
 11 ISG X       41      71
 12 END

Ended up on 12 lines, 22 bytes and no requirements on the stack or input.

Thanks for a funny challenge and great to see all nice solutions!

RPN rules! Wink

Cheers,
Thomas

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
10-09-2023, 06:05 AM (This post was last modified: 10-09-2023 07:41 AM by Werner.)
Post: #42
RE: 2023 RPN HHC Programming Contest
and here's mine: (19 bytes including END)

01 LBL "HHC"
02 PI
03 INT
04 ATAN
05 INT
06 LASTX
07 HR
08 %
09 INT
10 DEC
11 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
10-09-2023, 06:35 AM
Post: #43
RE: 2023 RPN HHC Programming Contest
Mine:
Code:

00 { 17-Byte Prgm }
01▸LBL "HHC"
02 PI
03 1/X
04 ACOS
05 IP
06 PI
07 COS
08 ATAN
09 PI
10 -
11 IP
12 END
Find all posts by this user
Quote this message in a reply
10-09-2023, 12:17 PM (This post was last modified: 10-09-2023 12:18 PM by Bernd Grubert.)
Post: #44
RE: 2023 RPN HHC Programming Contest
Here is mine:
Code:
01 LBL "HHC"
02 PI
03 INT
04 ATAN
05 INT
06 ENTER^
07 Σ+
08 10^X
09 LASTX
10 +
11 Σ+
12 MEAN
13 END

Unfortunately with 21 bytes a little larger than the previous solutions.

Anyway, thanks for the interesting challenge!
Find all posts by this user
Quote this message in a reply
10-09-2023, 01:24 PM
Post: #45
RE: 2023 RPN HHC Programming Contest
(10-09-2023 03:10 AM)Gerson W. Barbosa Wrote:  Anyway, it’s difficult to do it in 12 steps using this approach (an approximation for 41 or 71, the other obtained through the 30 units difference). Congratulations for managing to save two steps in your previous code!

Gerson.

Thank you for the byte counts and for your nice solution! It's always interesting to see what others had come up with! One of my early approaches was based on accumulating statistical registers and the similarity of congruence: \( 71 = 6(6+5)+5 \) and \( 41 = 6*6+5 \) or something similar with \( {71,41} \equiv 11 \mod 15 \) although the plain 41C does not have an easy way to recall the STAT x,x^2, y, y^2 registers without using RCL 11 or RCL 12 number keys.

I came to the conclusion there were too many steps to get that many 6, 5, and 11's on the stack! I also looked for some quick calculations that would let me poke the x,y stat registers to find a distribution that also had a MEAN or STDEV approximately 41 or 71, but this was also much harder starting from a empty stack.

I also respect Thomas's clever solution based on OEIS A254308! I have several python tools that can search for those kinds of sequences based on the downloaded full list, but didn't think to search there, very nice idea!

OEIS:
# OEIS Sequence Data (http://oeis.org/stripped.gz)
There are 198+ sequences that have 41 and 71 as consecutive entries.

Some interesting ( perhaps impractical) entries:
A002327 is also interesting as it allows \( a(n) = n^2-n-1 \) for \( x = {7,9} \)

A125202 \( a(n) = 4n^2 - 6n + 1 \) (similar to the ulam spiral generating functions!)

A064999 \(a(n) = \frac {n^3 + 3*n^2 + 2*n + 3} {3}\) - for obvious reasons this is impractical in a short program, but since it relies on \( a(4) \) and \( a(5) \) it is an interesting application of 1 to 5.

A260805 \( p = q^2 - 2*r^2 \) evaluated at \( (7,2) \) \( (11,5) \)

Gene, Thank you very much for the interesting challenge!! Would love to see the conference results!

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
10-09-2023, 01:44 PM (This post was last modified: 10-09-2023 01:54 PM by Eddie W. Shore.)
Post: #46
RE: 2023 RPN HHC Programming Contest
Here was mine (30 bytes, DM41X):

Code:
01 LBL^T HHC
02 10^X
03 ENTER
04 E^X
05 X^2
06 INT
07 RCL Y  
08 10^X
09 *
10 +               # 71 on the stack
11 ENTER        # 71 * 71% = 50.41
12 %
13 FRC
14 RCL T
15 10^X         
16 10^X
17 X^2
18 *                # 41 on the stack
19 END

Stack:
T: 0
Z: 0
Y: 71
X: 41
Visit this user's website Find all posts by this user
Quote this message in a reply
10-09-2023, 04:35 PM
Post: #47
RE: 2023 RPN HHC Programming Contest
(10-09-2023 01:24 PM)Allen Wrote:  I also respect Thomas's clever solution based on OEIS A254308!

I didn't start with a search, but I remembered that \(\frac{71}{41}\) is a pretty good approximation for \(\sqrt{3}\).
And so I tried to get smaller numbers by running the Fibonacci-like sequence backwards with:
Code:
01 ST-Y
02 X<>Y
03 END

To avoid negative values I had to swap \(x\) and \(y\) every now and then, but in the end I came up with:

y: 1
x: 1

That's a good starting point, I thought and reversed the process.
And then it occurred to me that I could make the main sequence a little shorter.

Only after I created the sequence did I look up if there was an easier way to do this.
But I couldn't find anything that would help.

We can generate increasingly better approximations for \(\sqrt{3}\) if we start with \(x = y = 1\) and iterate the following program:
Code:
01 +
02 ST+ L
03 LASTX
04 ST+ Y
05 END

y: 1
x: 1

R/S

y: 5
x: 3

R/S

y: 19
x: 11

R/S

y: 71
x: 41

R/S

y: 265
x: 153

R/S

y: 989
x: 571

R/S

y: 3,691
x: 2,131

R/S

y: 13,775
x: 7,953

Their quotient converge quite fast:

1.000000000
1.666666667
1.727272727
1.731707317
1.732026144
1.732049037
1.732050680
1.732050798
1.732050807
1.732050808
1.732050808


The reason is that these are the convergents of the periodic continued fraction of \(\sqrt{3} = [1;\overline{1,2}]\):

\(
\begin{align}
\frac{1}{1} &= [1;] \\
\\
\frac{5}{3} &= [1;1,2] \\
\\
\frac{19}{11} &= [1;1,2,1,2] \\
\\
\frac{71}{41} &= [1;1,2,1,2,1,2] \\
\cdots
\end{align}
\)

Thanks a lot for creating this contest and also for the many interesting contributions.
Find all posts by this user
Quote this message in a reply
10-09-2023, 04:35 PM (This post was last modified: 10-09-2023 04:39 PM by floppy.)
Post: #48
RE: 2023 RPN HHC Programming Contest
No INT and FRC (castrating effects).. a bit long.. with fenzy HHC 2023 letters inside ;-)

Code:
LBL "HHC"       ; x   y   z   t
CLX             ; 0   -   -   -
ISG X           ; 1   
"H"               
ISG X           ; 2
"H"
STO Z           ; 2   -   2   -
ISG X           ; 3   -   2   -
"C"
RCL Z           ; 2   3   -   2
X^2             ; 4   3   -   2
Y^X             ; 81  -   2   2
X<>Y            ; -  81   2   2
CLX             ; 0  81   2   2
10^X            ; 1  81   2   2
10^X            ; 10 81   2   2
-               ; 71  2   2   2
X<>Y            ; 2  71   2   2
ISG X           ; 3  71   2   2
"2023"
X^2             ; 9  71   2   2
CHS
R^              ; 2  -9   71  2
10^X            ; 100 -9  71  2 
R^              ; 2  100  -9  71  
/
+               ; 41  71  71  71
END

HP71B 4TH/ASM/Multimod, HP41CV/X/Y & Nov64d, PILBOX, HP-IL 821.62A & 64A & 66A, Deb11 64b-PC & PI2 3 4 w/ ILPER, VIDEO80, V41 & EMU71, DM41X
Find all posts by this user
Quote this message in a reply
10-09-2023, 04:36 PM (This post was last modified: 10-09-2023 04:40 PM by Peet.)
Post: #49
RE: 2023 RPN HHC Programming Contest
Many people seem to have chosen the same path for the 71, but the 41 seems to have numerous variations ... as the romans says ... all roads lead to 41.

Code:

01 LBL HHC     # 20 byte
02 PI
03 INT
04 ATAN
05 INT        # 71
06 X<>Y
07 COS
08 ATAN
09 PI
10 -
11 INT        # 41
12 END

My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C
Find all posts by this user
Quote this message in a reply
10-09-2023, 04:37 PM (This post was last modified: 10-09-2023 04:39 PM by born2laser.)
Post: #50
RE: 2023 RPN HHC Programming Contest
I took a hand at it too, longer in steps but at least according to V41-CX just 24 bytes (not as good as many here). I actually did it on 40 years old CV, but copied in the simulated CX to count bytes (lazy, I know).
Stack:
T: 11
Z: 11
Y: 71
X: 41

Code:

 01*LBL "HHC"
 02 10^X
 03 ENTER^
 04 10^X
 05 +
 06 LASTX
 07 ENTER^
 08 ENTER^
 09 +
 10 +
 11 +
 12 LASTX
 13 X<>Y
 14 +
 15 LASTX
 16 END
Find all posts by this user
Quote this message in a reply
10-10-2023, 09:11 AM
Post: #51
RE: 2023 RPN HHC Programming Contest
I had a couple of attempts in using the 11c RAN# function for the challenge. This sequence gets 71 on the stack:

Code:

RAN#
RAN#
RAN#
/
ACOS
INT

I never figured out how to get 41 from the first two RAN# commands. / ACOS INT gives 82.
Find all posts by this user
Quote this message in a reply
10-10-2023, 10:20 AM
Post: #52
RE: 2023 RPN HHC Programming Contest
Hello!

(10-10-2023 09:11 AM)Paul Dale Wrote:  I had a couple of attempts in using the 11c RAN# function for the challenge. This sequence gets 71 on the stack:
...
I never figured out how to get 41 from the first two RAN# commands. / ACOS INT gives 82.

That's an interesting and very unusual approach! But how do you make it work? On my HP-11C, no matter what I use to seed the random number generator with, I don't get "41" and/or "71" as a result.

Regards
Max
Find all posts by this user
Quote this message in a reply
10-10-2023, 03:37 PM (This post was last modified: 10-11-2023 07:38 PM by Jeff O..)
Post: #53
RE: 2023 RPN HHC Programming Contest
Slight improvement, now only 18 steps, but still (annoyingly) 28 bytes, so hard to call it much of an improvement. Figured out that while "STO+ ST X" does not copy X to Last X, "RCL+ ST X", which accomplishes the same thing, does copy X to Last X, allowing the "X<>Y" to be eliminated. But I guess "RCL+ ST X" takes more bytes than "STO+ ST X", offsetting the savings from removing "X<>Y". Still feels a little better.
Code:
00 { 28-Byte Prgm }
01▸LBL "HHC"
02 SIGN
03 RCL+ ST X
04 LASTX
05 E↑X
06 FP
07 RCL ST Y
08 10↑X
09 ×
10 IP
11 RCL ST Y
12 SQRT
13 FP
14 RCL ST Z
15 10↑X
16 ×
17 IP
18 END
Quick and dirty, 19 steps, 28 bytes (on Free42/42S, assume the same on a 41). Just extract the "71" from e, and the "41" from square root of 2:
Code:

00 { 28-Byte Prgm }
01▸LBL "HHC"
02 SIGN
03 E↑X
04 LASTX
05 STO+ ST X
06 X<>Y
07 FP
08 RCL ST Y
09 10↑X
10 ×
11 IP
12 RCL ST Y
13 SQRT
14 FP
15 RCL ST Z
16 10↑X
17 ×
18 IP
19 END

Dave - My mind is going - I can feel it.
Find all posts by this user
Quote this message in a reply
10-11-2023, 07:00 PM
Post: #54
RE: 2023 RPN HHC Programming Contest
Gene? Posts of, in person, winning RPN Contest solutions from Jason and Craig?? If I recall, correctly, there was a tie.
~ Jim J. ~
Find all posts by this user
Quote this message in a reply
10-11-2023, 10:46 PM
Post: #55
RE: 2023 RPN HHC Programming Contest
(10-10-2023 10:20 AM)Maximilian Hohmann Wrote:  That's an interesting and very unusual approach! But how do you make it work? On my HP-11C, no matter what I use to seed the random number generator with, I don't get "41" and/or "71" as a result.

It won't directly, the idea was to get a non-zero value onto the stack using RAN# and then manipulate it into the required form. Because the rules specified a memory lost starting state, the random sequence is entirely predictable.

All of the other solutions needed to go from a stack of zeros to something non-zero (e^x, ACOS, pi, ...). This was a different way of doing it that which didn't work out.

Pauli
Find all posts by this user
Quote this message in a reply
10-12-2023, 10:52 AM
Post: #56
RE: 2023 RPN HHC Programming Contest
(10-09-2023 04:27 AM)Paul Dale Wrote:  I found one other approach for the first half 71, but I don't consider it as pure since it relies on a zero on the stack:
Code:

ACOS ->DEG SQRT INT

If a clear stack is assumed then at least one 10-step solution is possible;

Code:

 01 LBL "HHC"
 02 ACOS
 03 PI
 04 INT
 05 ST/ Y
 06 %
 07 ATAN
 08 INT
 09 ST+ Y
 10 END

20 bytes, though.

I don’t like the idea of counting with a zero on the stack either.
Find all posts by this user
Quote this message in a reply
10-12-2023, 11:13 AM
Post: #57
RE: 2023 RPN HHC Programming Contest
Who won?

HP71B 4TH/ASM/Multimod, HP41CV/X/Y & Nov64d, PILBOX, HP-IL 821.62A & 64A & 66A, Deb11 64b-PC & PI2 3 4 w/ ILPER, VIDEO80, V41 & EMU71, DM41X
Find all posts by this user
Quote this message in a reply
10-13-2023, 05:51 AM
Post: #58
RE: 2023 RPN HHC Programming Contest
(10-12-2023 11:13 AM)floppy Wrote:  Who won?

And what is the winning program?
Find all posts by this user
Quote this message in a reply
10-14-2023, 03:30 AM
Post: #59
RE: 2023 RPN HHC Programming Contest
(10-09-2023 01:24 PM)Allen Wrote:  OEIS:
# OEIS Sequence Data (http://oeis.org/stripped.gz)
There are 198+ sequences that have 41 and 71 as consecutive entries.

Some interesting ( perhaps impractical) entries:
A002327 is also interesting as it allows \( a(n) = n^2-n-1 \) for \( x = {7,9} \)

13 steps and 26 bytes. Not enough for a winning solution, but definitely not impractical..
Find all posts by this user
Quote this message in a reply
10-16-2023, 02:31 AM
Post: #60
RE: 2023 RPN HHC Programming Contest
indeed.. the others are less practical as they require too many terms for a short program!

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
Post Reply 




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