Post Reply 
Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
02-17-2017, 11:54 PM
Post: #17
RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant
(02-17-2017 09:50 PM)Claudio L. Wrote:  
(02-17-2017 01:58 PM)Gerson W. Barbosa Wrote:  HP-50g (50 bytes)

« 0. 1. DUP2 5. ROLL

START SWAP OVER + ROT OVER INV + UNROT

NEXT DROP2

»

Here's an alternative, using local variables and lists for readability:
Code:

« → N 
    «
     1 1
     3 N START DUP2 + NEXT
     N →LIST 
     INV ∑LIST
   »
»

I didn't measure on stock firmware since I have my calc with newRPL, but for comparison your code was 72 bytes in newRPL and the alternative is 80 bytes.
One glitch: it only works for N=3 and higher.

59 bytes in RPL.

(02-17-2017 09:50 PM)Claudio L. Wrote:  Just a different point of view.

Also, a great idea. Thank you very much for your contribution!

This modified stack-only version is 1.5 bytes longer. The glitch still persists for N=1, but only because ∑LIST doesn't accept one-element lists, at least here in old RPN.

Gerson.

Code:

« 0. { } 1. 1. 5. ROLL
  START PICK3 + DUP UNROT + ROT
  NEXT ROT DROP2 INV ∑LIST
»
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming exercise (RPL/RPN) - Reciprocal Fibonacci Constant - Gerson W. Barbosa - 02-17-2017 11:54 PM



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