Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions golden_ratio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def golden_ratio(iterations=15):
# Start with an initial approximation of the golden ratio, typically 1.
ratio = 1

# Iterate to improve the approximation.
for _ in range(iterations):
# The golden ratio is defined as (1 + sqrt(5)) / 2.
# We can approximate it by adding 1 to the reciprocal of the current approximation.
# This approach iteratively refines the approximation.
ratio = 1 + 1 / ratio

return ratio

# Example usage:
approximations = []
for i in range(1, 16):
approximation = golden_ratio(i)
approximations.append(approximation)

print("Approximations of the Golden Ratio:")
for i, approx in enumerate(approximations):
print(f"Iteration {i+1}: {approx:.16f}")