φ Generator

This program generates φ, also called the golden ratio. It creates the fibonacci sequence \big\{1, 1, 2, 3, 5, 8, 13, \dots\big\} and divides the newly generated number by the last one. In theory this program would generate exactly φ.Terminal Output

Fibonacci sequence

\text{Start: } x_1 = 1 \text{ and } x_2 = 1
\text{Generation: } x_n = x_{n-1} + x_{n-2}

1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13
8 + 13 = \dots

The golden ratio (φ)

\phi \text{ is the ratio between } x_n \text{ and } x_{n-1}\text{.}
\phi = \frac{x_n}{x_{n-1}}


# Python 2.7.7 Code
# Jonathan Frech 6th of April, 2015

# begin
x1, x2 = 1, 1

# create fibonacci sequence to the 1000th number (integer overflow)
for _ in range(0, 1000):
	# print out phi
	print "phi = " + str(float(x2) / x1)
	
	# generate fibonacci
	x = x1 + x2
	x1 = x2
	x2 = x
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s