def problem25(): """ 1000-digit Fibonacci number What is the index of the first term in the Fibonacci sequence to contain 1000 digits? """ for index, fibonacci in enumerate(mathhelper.fibonacci_list(None)): if len(str(fibonacci)) == 1000: return index + 1
def test_fibonacci_list(self): self.assertEqual(list(mathhelper.fibonacci_list(-5)), []) self.assertEqual(list(mathhelper.fibonacci_list(-1)), []) self.assertEqual(list(mathhelper.fibonacci_list(0)), []) self.assertEqual(list(mathhelper.fibonacci_list(1)), [1, 1]) self.assertEqual(list(mathhelper.fibonacci_list(2)), [1, 1, 2]) self.assertEqual(list(mathhelper.fibonacci_list(3)), [1, 1, 2, 3]) self.assertEqual(list(mathhelper.fibonacci_list(10)), [1, 1, 2, 3, 5, 8]) self.assertEqual(list(mathhelper.fibonacci_list(144)), [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144])
def problem2(): """ Even Fibonacci numbers By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. """ return_value = 0 for number in mathhelper.fibonacci_list(4000000): if number % 2 == 0: return_value += number return return_value