Look-and-say sequence: Difference between revisions

Line 1,212:
<pre>["1", "11", "21", "1211", "111221", "312211", "13112221", "1113213211"]</pre>
 
===ShortBegginer 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] );
Line 1,227 ⟶ 1,225:
return result.data;
}
void main(){
{
auto s="1";
for(auto i=0; i<10; i++)
(s = s.lookAndSay).writeln;
}</lang>
 
===Fast Imperative Version===
<lang d>import core.stdc.stdio, std.math, std.conv, std.algorithm, std.array;
Anonymous user