Skip to content

Instantly share code, notes, and snippets.

@Winston-Lin-9527
Last active January 16, 2023 02:04
Show Gist options
  • Save Winston-Lin-9527/ebe9a1af69d104aeb9be1845582b5985 to your computer and use it in GitHub Desktop.
Save Winston-Lin-9527/ebe9a1af69d104aeb9be1845582b5985 to your computer and use it in GitHub Desktop.
finding the smallest fib sum with 1 chance for restart
def fib(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
fib_list = list(fib(99))
min_sum = (sum(fib_list), 0)
print(f"test: {min_sum}")
list_len = len(fib_list)
for i in range(list_len):
sum_for_this = sum(fib_list[0:i])+sum(list(fib(list_len-i)))
print (f"sum:{sum_for_this} for {i}")
if sum_for_this < min_sum[0]:
min_sum = (sum_for_this, i)
print(f"\n{min_sum}")
# it happens to be the middle one every time, not sure about proof yet..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment