Ludic numbers: Difference between revisions

Content added Content deleted
m (used a consistent color for a highlighted numeral, used a more visible ellipse.)
Line 2,726: Line 2,726:


=={{header|zkl}}==
=={{header|zkl}}==
This solution builds a stack of iterators, one for each Ludic number, each extending the previous iterator. A "master" iterator sits atop the stack and provides the interface to the stack. When the next Ludic number is requested, a "pulse train" ripples down and up and down ... the stack as numbers are crossed off the list(s) (figure of speech, no numbers are cached).
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){
if(n==2) return(seq.tweak(fcn(n){ if(n.isEven) Void.Skip else n })); // uggg, special case
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 }.fp(Ref([2..]))).push(1);
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();