Function Repository Resource:

FibonacciEncode

Source Notebook

Fibonacci-digit encoding for a number

Contributed by: Wolfram Staff (original content by Stephen Wolfram)

ResourceFunction["FibonacciEncode"][n]

gives the Fibonacci-digit encoding for the number n.

Details and Options

Fibonacci encoding is made unique by allowing no pair of 1s to appear together.

Examples

Basic Examples (1) 

Fibonacci encoding for 42:

In[1]:=
ResourceFunction["FibonacciEncode"][42]
Out[1]=

Scope (1) 

The Fibonacci encoding of a large integer:

In[2]:=
ResourceFunction["FibonacciEncode"][1*^100]
Out[2]=

Properties and Relations (2) 

Get the Fibonacci encoding for a random integer:

In[3]:=
n = RandomInteger[10000]
Out[3]=
In[4]:=
enc = ResourceFunction["FibonacciEncode"][n]
Out[4]=

Decode the encoding to retrieve the original integer:

In[5]:=
Total[MapIndexed[Fibonacci[#2[[1]] + 1]*#1 &, Reverse[enc]]]
Out[5]=

Neat Examples (1) 

Visualize the Fibonacci encoding for the first 30 integers:

In[6]:=
ArrayPlot[
 PadLeft[Table[ResourceFunction["FibonacciEncode"][n], {n, 30}]], Mesh -> True]
Out[6]=

Version History

  • 2.0.0 – 02 September 2020
  • 1.0.0 – 20 November 2019

Related Resources

License Information