I am trying to work on a problem and part of the solution is to find the sum of finbonacci numbers that is less than an input number. Now the upper limit of the input number is 10**9. I have reduced the problem to the following O(n) solution, I was wondering if there is a more efficient solution.
b=[1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609, 986, 1596, 2583, 4180, 6764,
10945, 17710, 28656, 46367, 75024, 121392, 196417, 317810, 514228, 832039,
1346268, 2178308, 3524577, 5702886, 9227464, 14930351, 24157816,
39088168, 63245985, 102334154, 165580140, 267914295, 433494436, 701408732, 1134903169, 1836311902]
def test_lambda(a):
list_numbers= filter(lambda x: x<=a, b)
return len(list_numbers)
As you can see I am comparing the values of the list b with the given input and returning the elements that are less than the given number.
b is the list of sum of fibonaccis numbers upto that index, so the 1st number is 1, the sum is 1, the 2nd is 1 the sum is 2, the 3rd 2 the sum 4...