Ludic numbers: Difference between revisions
Content added Content deleted
m (used a consistent color for a highlighted numeral, used a more visible ellipse.) |
(→{{header|zkl}}: rewrite) |
||
Line 2,726: | Line 2,726: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
This solution builds |
This solution builds an iterator with filters, one for each Ludic number, each extending the previous filter. A "master" iterator sits at the top and provides the interface. When the next Ludic number is requested, the next odd number sent down the list of filters and if it makes to the end, it is the next Ludic number. A new filter is then attached [to the iterator] with a starting index of 1 and which indexes to strike. |
||
<lang zkl>fcn dropNth(n,seq){ |
<lang zkl>fcn dropNth(n,seq){ |
||
seq.tweak(fcn(n,skipper,idx){ if(0==idx.inc()%skipper) Void.Skip else n } |
|||
.fp1(n,Ref(1))) // skip every nth number of previous sequence |
|||
seq.tweak(fcn(n,skipper,w){ if(0==(w.idx+1)%skipper) Void.Skip else n }.fp1(n), |
|||
Void.Void,Void.Void,True); |
|||
} |
} |
||
fcn ludic{ //-->Walker |
fcn ludic{ //-->Walker |
||
Walker(fcn(rw){ w:=rw.value; n:=w.next(); rw.set(dropNth(n,w)); n } |
Walker(fcn(rw){ w:=rw.value; n:=w.next(); rw.set(dropNth(n,w)); n } |
||
.fp(Ref([3..*,2]))) // odd numbers starting at 3 |
|||
.push(1,2); // first two Ludic numbers |
|||
}</lang> |
}</lang> |
||
<lang zkl>ludic().walk(25).toString(*).println(); |
<lang zkl>ludic().walk(25).toString(*).println(); |