def fib(n, b, l):
xs = [[1, 0]]
for _ in range(n + 1):
new_xs = []
ad = 0
for x, y in xs:
if y < l:
new_xs.append([x, y + 1])
for x, y in new_xs:
if y > 1:
ad += x
if ad > 0:
new_xs.append([ad * b, 0])
xs = new_xs
print("adults :", ad, xs)
print(xs)
return sum(x for x, y in xs if y > 0)
r = fib(8, 3, 4)
print(r)
[[12, 4], [18, 3], [54, 2], [99, 1], [252, 0]]
To embed this program on your website, copy the following code and paste it into your website's HTML: