# Zeckendorf Representations

The following image is a graph of Zeckendorf representations of numbers 1 through 232:

“Zeckendorf’s theorem states that every positive integer can be represented uniquely as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers.”

The above is quoted from:

The graph is constructed of vertical bars that represent the Fibonacci numbers that comprise the Zeckendorf representations of integers, n. The values of n range from 1 through 232 from left to right. Bars are drawn downward from the top of the graph. The height of each bar is proportional to the value of the Fibonacci number that it represents. For each n, the bars are drawn in order from tallest to shortest, with shorter bars superimposed over upper portions of taller ones, leaving the lower portions all bars at least partially visible.

The hue of the fill of each bar is based on the value of the Fibonacci number that it represents. The bars are drawn with no stroke, so adjacent bars that represent equal values merge to form areas of uniform color.

Code for Processing Python Mode:

``````# Graph of Zeckendorf Representations

# Set the phase of the hue cycle
hue_phase = 9

# Create a list of positive Fibonacci numbers
def fib(n):
# modified from https://www.python.org/
f = []
a, b = 1, 2
while a <= n:
f.append(a)
a, b = b, a + b
return f
fibs = fib(233)

def zeckendorf(n):
# Recursive function to return the Zeckendorf representation of n as a list
if n in fibs:
return [n]
else:
i = 0
while n > fibs[i]:
i += 1
f = fibs[i - 1]
l = [f]
l.extend(zeckendorf(n - f))
return l

def setup():
size(935, 438)
colorMode(HSB, len(fibs) - 1, 100, 100, 100)
noLoop()
noStroke()
background(0, 0, 0)

def draw():
# Draw graph of Zeckendorf representations for numbers 1 through 232
for n in range(1, 233):
for f in zeckendorf(n):
# Calculate hue of fill
fill((hue_phase + fibs.index(f)) % len(fibs), 100, 100, 100)
rect(n * 4, 3, 4, f * 3)
``````
3 Likes