With an = (an-2 + 1)×an-1
with a0 = 0
and a1 = 1
formula find dummy_numbers(max)
My code:
def dummy_numbers(nums):
binsize = (((nums - 2) +1) * (nums -1))
return map(lambda x: int(nums + binsize * x), range(nums))
for num in dummy_numbers(10):
print(num)
my code prints different result than I expected
Use an actual generator with
yield
to make this easier. The tricky part here is keeping track ofan-1
andan-2
as you iterate. This can be achieve like so:You also need to hardcode in the constant value that get returned for
0
and1
:Outputs:
You could also make this non-recursive like so: