RosettaCodeData/Task/Look-and-say-sequence/Pure/look-and-say-sequence.pure
2023-07-01 13:44:08 -04:00

14 lines
420 B
Text

using system;
// Remove the trailing "L" from the string representation of bigints.
__show__ x::bigint = init (str x);
say x = val $ strcat $ map (sprintf "%d%s") $ look $ chars $ str x with
look [] = [];
look xs@(x:_) = (#takewhile (==x) xs,x) : look (dropwhile (==x) xs);
end;
iteraten 5 say 1; // [1,11,21,1211,111221]
// This prints the entire sequence, press Ctrl-C to abort.
do (puts.str) (iterate say 1);