RosettaCodeData/Task/Look-and-say-sequence/Metafont/look-and-say-sequence.metafont
2020-02-17 23:21:07 -08:00

23 lines
403 B
Text

vardef lookandsay(expr s) =
string r; r := "";
if string s:
i := 0;
forever: exitif not (i < length(s));
c := i+1;
forever: exitif ( (substring(c,c+1) of s) <> (substring(i,i+1) of s) );
c := c + 1;
endfor
r := r & decimal (c-i) & substring(i,i+1) of s;
i := c;
endfor
fi
r
enddef;
string p; p := "1";
for el := 1 upto 10:
message p;
p := lookandsay(p);
endfor
end