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 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
Fibonacci 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 RCL05
45 FIX 2
display least significant term 46 STOP
ready 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)