Mini-Challenge: Rudin-Shapiro Sequence
|
12-16-2022, 10:41 PM
(This post was last modified: 12-16-2022 10:42 PM by John Keith.)
Post: #11
|
|||
|
|||
RE: Mini-Challenge: Rudin-Shapiro Sequence
As promised, here are my solutions to this challenge.
First, a 97 byte program for any RPL calculator. This is a simple implementation of the recurrence from the Wikipedia article. Given a number n on the stack, returns 2n+1 terms. An input of 500 returns 1001 terms in 3.25 seconds on my 50g. Code:
Next, a larger but faster version which avoids the 2 MOD test but requires extra code to avoid problems with odd number inputs. 121 bytes. An input of 500 returns 1000 terms in 1.94 seconds on my 50g. Code:
Next, a completely different sort of program which requires the 48G or newer because it uses the listability of functions (called "automatic list processing" in the manuals). Given a number n on the stack, returns 2^n terms. For example an input of 10 will return 1024 terms in 1.22 seconds on my 50g. 55 bytes. Code:
Finally, a similar program for u(n) aka A014081. Also returns 2^n terms, 55.5 bytes. An input of 10 returns 1024 terms in 1.19 seconds. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)