# HP Forums

Full Version: (41) Integer Decomposing (fibonacci number system)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from Number Theory in Science and Communication, M.R. Schroeder, second enlarged edition, Springer-Verlag {pgs. 346-348}
PHP Code:
`C. A Calculator Program for Decomposing an Integer According to theFibonacci Number SystemTo call the program, press     GTO "FNS"and enter the integer to be decomposed, for example,     1000 .Then press     R/Sto start the calculation. The display will show in rapid succession theFibonacci decomposition of 1000 and the least significant term once morewith two zeroes after the decimal point (because this is important in awinning strategy for nim-like games; see Chap. 5):     987.     13.     13.00More specifically, in such a parlor game, when confronted with a pile of 1000chips, take 13 away to start your winning strategy. (Rules of the game: Noplayer can take more than twice the number of chips his predecessor justtook, but each player must take at least one chip, and the first player may nottake all the chips. He who takes the last chip(s) wins.)                            Listing for "FNS"_________________________________________________________Comment                                  Step  Code_________________________________________________________                                         01     LBL "FNS"initialize by calculating                02     5two 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     RDNsubroutine for                           13     LBL 14storing new integersubroutine for                           14     STO 04Fibonacci decomposition                                         15     LBL 15                                         16     0                                         17     RCL 04decomposition completed?                 18     x ≤ y?                                         19     GTO 13                                         20     RCL 01                                         21     •                                         22     LNhyperbolic cosine                        23     COSHfrom 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 0display Fibonacci decomposition          39     PSE                                         40     ST- 04                                         41     STO 05                                         42     GTO 12subroutine for recalling and             43     LBL 13displaying least significant term        44     RCL05                                         45     FIX 2display least significant term           46     STOPready to start over                      47     GTO 14                                         48     END `
real gems are yet to be revealed from 'obscure' sources.

BEST!
SlideRule

ps: follow-on to this thread, HP-41 Modulo function, in the General Forum HP Calculators (and very old HP Computers)
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :