def main(): index = 1 for term in fibonacci_generator(): if len(str(term)) >= 1000: print(index) break index += 1
def main(): result = 0 for i in fibonacci_generator(): if i >= limit: break if i%2 == 0: result += i print(result)
def p25(): """ 1000-digit Fibonacci number The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: 1 2 3 4 5 6 7 8 9 10 11 12 (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144) The 12th term, F12, is the first term to contain three digits. What is the index of the first term in the Fibonacci sequence to contain 1000 digits? """ import sys sys.path.append("../idea bag/") from fibonacci import fibonacci_generator index = 0 number = 0 fibonacci_number = fibonacci_generator() while len(str(number)) < 1000: number = next(fibonacci_number) index += 1 return index