Lazy Sequences that "Look Ahead" for Project Euler Problem 14
- by ivar
I'm trying to solve Project Euler Problem 14 in a lazy way. Unfortunately, I may be trying to do the impossible: create a lazy sequence that is both lazy, yet also somehow 'looks ahead' for values it hasn't computed yet.
The non-lazy version I wrote to test correctness was:
(defn chain-length [num]
(loop [len 1
n num]
(cond
(= n 1)…