(41) Fibonacci Decomposition (integer)
|
04-05-2020, 12:48 AM
(This post was last modified: 04-05-2020 11:24 AM by SlideRule.)
Post: #1
|
|||
|
|||
(41) Fibonacci Decomposition (integer)
Pages 347 & 348 from Number Theory in Science and Communication, Second Enlarged Edition, © Sprinler·Veriag Berlin Heidelberg 1984 and 1986, ISBN 978-3-662-22246-1 (eBoook)
"C. A Calculator Program for Decomposing an Integer According to the Fibonacci Number System To call the program, press GTO "FNS" and enter the integer to be decomposed, for example, 1000. Then press R/S to start the calculation. The display will show in rapid succession the Fibonacci decomposition of 1000 and the least significant term once more with two zeroes after the decimal point (because this is important in a winning strategy for nim-like games; see Chap. 5): 987. 13. 13.00 More specifically, in such a parlor game, when confronted with a pile of 1000 chips, take 13 away to start your winning strategy. (Rules of the game: No player can take more than twice the number of chips his predecessor just took, but each player must take at least one chip, and the first player may not take all the chips. He who takes the last chip(s) wins.) Listing for "FNS" Comment Step Code 01 LBL "FNS" initialize by calculating 02 5 two constants 03 SQRT √5 04 STO 01 05 1 06 + 07 0.5 08 * Golden Ratio 09 STO 02 10 LN 11 STO 03 12 RDN subroutine for 13 LBL 14 storing new integer subroutine for 14 STO 04 Fibonnacci decomposition 15 LBL 15 16 0 17 RCL 04 decomposition completed? 18 x ≤ y ? 19 GTO 13 20 RCL 01 21 * 22 LN hyperbolic cosine 23 COSH from MATH 1 24 2 25 * 26 LN 27 RCL 03 28 / 29 INT 30 RCL 02 31 x < > y 32 y^x 33 RCL 01 34 / 35 0.5 36 + 37 INT 38 FIX 0 display Fibonacci decomposition 39 PSE 40 ST- 04 41 STO 05 42 GTO 12 subroutine for recalling and 43 LBL 13 displaying least significant term 44 RCL 05 45 FIX 2 display least significant term 46 STOP ready to start over 47 GTO 14 48 END" BEST! SlideRule |
|||
06-25-2022, 02:10 AM
Post: #2
|
|||
|
|||
RE: (41) Fibonacci Decomposition (integer)
This shorter program for the HP-42S may take a bit longer especially for bigger numbers:
Code: 00 { 27-Byte Prgm } You may want to add a VIEW Y command at the end. Examples 65 XEQ "FNS" y: 55 x: 10 R/S y: 8 x: 2 R/S y: 2 x: 0 Therefore: \(65 = 55 + 8 + 2\) 1000 XEQ "FNS" y: 987 x: 13 R/S y: 13 x: 0 Therefore: \(1000 = 987 + 13\) References |
|||
06-25-2022, 08:15 AM
Post: #3
|
|||
|
|||
RE: (41) Fibonacci Decomposition (integer)
It's easy to translate the program for the HP-15C:
Code: 001 { 0 } 0 Only the usage slightly changes. Example CLEAR PRGM 65 R/S 55.0000 R/S 10.0000 R/S 8.0000 R/S 2.0000 R/S 2.0000 R/S 0.0000 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)