Python :
>>> from itertools import *
Define a recursive function (see R Sahu answer)
>>> f = lambda x: 1 if x<0 else (x-1) + 2*f(x-1)
Then use the function dropwhile()
to remove elements from the list [0, 1, 2, 3, ....] for which f(x)<=1000000
, resulting in a list of integers for which f(x) > 1000000
. Note: count()
returns an infinite "list" of [0, 1, 2, ....]
The function dropwhile()
returns a Python generator, so we use next()
to get the first value of the list:
>>> next(dropwhile(lambda x: f(x)<=1000000, count()))
19
source
share