Hi Laurent, > I am playing around with Problem 35 on Project Euler and just stumbled on > this: > > (de split-number (N) > (mapcar format (chop (format N))) ) > > (de all-rotations (N) > (let SN (split-number N) > (make > (for L (range 1 (length SN)) > (link (rot SN)) > (println SN) ) ) ) ) > > : (all-rotations 123) > (3 1 2) > (2 3 1) > (1 2 3) > -> ((1 2 3) (1 2 3) (1 2 3)) > > I can't understand why I do not get the same result as the println.
The problem is that 'rot' is a "destructive" function, i.e. it modifies its list argument. You could use 'copy' to avoid this. I would write (de split-number (N) (mapcar format (chop N)) ) (de all-rotations (N) (let SN (split-number N) (make (do (length SN) (link (copy (rot SN))) (println SN) ) ) ) ) (two minor optimizations: 'chop' can also directly work on a number, and 'L' is not needed in the loop). Cheers, - Alex -- UNSUBSCRIBE: mailto:email@example.com?subject=Unsubscribe