Jump to content

Zeckendorf number representation: Difference between revisions

m (→‎{{header|QuickBASIC}}: Constants TRUE% and FALSE% for better readability.)
Line 3,350:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">zeckendorf[0] = 0;
ZeckendorfRepresentation[0] = 0;
zeckendorf[n_Integer] :=
ZeckendorfRepresentation[n_Integer?Positive] :=
10^(# - 1) + zeckendorf[n - Fibonacci[# + 1]] &@
FromDigits@NumberDecompose[n, Reverse@Fibonacci@Range[2,1000]];
LengthWhile[
zeckendorfZeckendorfRepresentation /@ Range[0, 20]</syntaxhighlight>
Fibonacci /@
Range[2, Ceiling@Log[GoldenRatio, n Sqrt@5]], # <= n &];
zeckendorf /@ Range[0, 20]</syntaxhighlight>
{{Out}}
<pre>{0, 1, 10, 100, 101, 1000, 1001, 1010, 10000, 10001, 10010, 10100,
4

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.