OEIS A244953: Ridiculous Formula
|
08-27-2022, 12:22 PM
(This post was last modified: 08-27-2022 03:40 PM by Allen.)
Post: #13
|
|||
|
|||
RE: OEIS A244953: Ridiculous Formula
Good morning and thank you for an interesting discussion.
Thomas, nice work on the formula!! From a different approach, I arrived at a surprisingly similar routine (perhaps the exact same formula but factored differently?) that saves two steps (5 bytes) in RPL and 2 bytes in RPN by reusing the intermediate value \( \begin{align} 3n \mod 4 \end{align} \) . Originally, I spent some time trying to implement a different formula, which still might be possible, \( \begin{align} a(n) = 6 \lfloor{\frac n 4}\rfloor + \frac{7(n \mod 4) - (n \mod 4)^2}{2} \end{align} \) but arrived a something very similar to Thomas' elegant formula from last week: \( \begin{align} a(n) = \frac{3n + 4(3n \mod 4) - (3n \mod 4)^2}{2} \end{align} \) The formula looks uglier, but is slightly more efficient to calculate with only 6 mathematical operations and 2 less commands in RPL. Code:
Somehow I feel the stack lifts could be optimized here to replicate the DUP function from RPL, but I've gotten rusty during covid. Code:
or python Code:
17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)