Zeckendorf number representation: Difference between revisions

m
→‎{{header|QuickBASIC}}: Constants TRUE% and FALSE% for better readability.
(→‎{{header|QuickBASIC}}: Added a solution.)
m (→‎{{header|QuickBASIC}}: Constants TRUE% and FALSE% for better readability.)
Line 968:
DECLARE FUNCTION ToZeckendorf$ (N%)
' The maximum Fibonacci number that can fit in a
' 32 bit number is Fib&(45)
CONST MAXFIBINDEX% = 45, TRUE% = -1, FALSE% = 0
DIM SHARED Fib&(1 TO MAXFIBINDEX%)
Fib&(1) = 1: Fib&(2) = 2
Line 996:
' If we found a digit, build the representation
IF FPos% >= 1 THEN ' have a digit
SkipDigit% = 0FALSE%
WHILE FPos% >= 1
IF Rest% <= 0 THEN
Result$ = Result$ + "0"
ELSEIF SkipDigit% THEN ' we used the previous digit
SkipDigit% = 0FALSE%
Result$ = Result$ + "0"
ELSEIF Rest% < Fib&(FPos%) THEN ' cannot use the digit at FPos%
SkipDigit% = 0FALSE%
Result$ = Result$ + "0"
ELSE ' can use this digit
SkipDigit% = -1TRUE%
Result$ = Result$ + "1"
Rest% = Rest% - Fib&(FPos%)
511

edits