fork download
  1. def unfold(f, x):
  2. while x is not None:
  3. yield x
  4. x = f(x)
  5.  
  6. def next_elem(t):
  7. (a, b, c, d) = t
  8. return (b, c, d, a*(a+1))
  9.  
  10. logical = unfold(next_elem, (4, 5, 6, 8))
  11.  
  12. for n in logical:
  13. print(n)
  14. if n[-1] > 1000:
  15. break
Success #stdin #stdout 0.11s 14120KB
stdin
Standard input is empty
stdout
(4, 5, 6, 8)
(5, 6, 8, 20)
(6, 8, 20, 30)
(8, 20, 30, 42)
(20, 30, 42, 72)
(30, 42, 72, 420)
(42, 72, 420, 930)
(72, 420, 930, 1806)