Kolakoski sequence: Difference between revisions

Content added Content deleted
m (→‎{{header|zkl}}: get rid of variables)
Line 340: Line 340:
{{trans|Python}}
{{trans|Python}}
<lang zkl>fcn kolakoski(start_items=List(1,2), length=20){ //-->List
<lang zkl>fcn kolakoski(start_items=List(1,2), length=20){ //-->List
s,rk,cw := List(), Ref(0), Walker.cycle(start_items).next;
Walker.tweak(fcn(s,rk,cw){ // infinite iterator
Walker.tweak(fcn(s,rk,cw){ // infinite iterator
s.append( c_next:=cw() );
s.append( c_next:=cw() );
sk:=s[rk.inc()]; // inc returns previous value, ie k++
sk:=s[rk.inc()]; // inc returns previous value, ie k++
if(sk>1) s.extend((List.createLong(sk - 1,c_next))); // list of sk cn's
if(sk>1) s.extend((List.createLong(sk - 1,c_next))); // list of sk cn's
sk // where we are in s, not end of s
sk
}.fp(List(), Ref(0), Walker.cycle(start_items).next) )
}.fp(s,rk,cw) ).walk(length); // iterate length times
.walk(length); // iterate length times, return list
}</lang>
}</lang>
<lang zkl>fcn _run_len_encoding(truncated_series){ //List-->List
<lang zkl>fcn _run_len_encoding(truncated_series){ //List-->List