Look-and-say sequence: Difference between revisions

Line 1,212:
<pre>["1", "11", "21", "1211", "111221", "312211", "13112221", "1113213211"]</pre>
 
===Short Imperative Version===
<lang d>import std.stdio, std.conv, std.array;
 
auto lookAndSay(string s)
{
auto result = appender!string;
auto i=0, j=i+1;
while(i<s.length)
{
while(j<s.length && s[i]==s[j]) j++;
result.put( text(j-i) ~ s[i] );
i = j++;
}
return result.data;
}
void main()
{
auto s="1";
for(auto i=0; i<10; i++)
(s = s.lookAndSay).writeln;
}</lang>
===Fast Imperative Version===
Same output.
Anonymous user