Intersecting number wheels: Difference between revisions

Content added Content deleted
(→‎{{header|zkl}}: added code)
m (→‎{{header|zkl}}: change initial data structure)
Line 465: Line 465:


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>fcn intersectingNumberWheelsW(wheel1, wheel2, etc){ // ("A",(a,b,"C")), ("C",(d,e)) ...)
<lang zkl>fcn intersectingNumberWheelsW(wheels){ // ("A":(a,b,"C"), "C":(d,e) ...)
ws:=vm.arglist.pump(Dictionary().add,fcn(w){ return(w[0],Walker.cycle(w[1])) });
ws:=wheels.pump(Dictionary(),fcn([(k,v)]){ return(k,Walker.cycle(v)) }); // new Dictionary
Walker.zero().tweak(fcn(w,wheels){
Walker.zero().tweak(fcn(w,wheels){
while(1){
while(1){
Line 472: Line 472:
if(Int.isType(w)) return(w);
if(Int.isType(w)) return(w);
}
}
}.fp("A",ws)) // assume wheel A exists and is always first
}.fp(wheel1[0],ws))
}</lang>
}</lang>
<lang zkl>wheelSets:=T( T( T("A",T(1,2,3)) ),
<lang zkl>wheelSets:=T( Dictionary("A",T(1,2,3)),
T( T("A",T(1,"B",2)), T("B",T(3,4)) ),
Dictionary("A",T(1,"B",2), "B",T(3,4)),
T( T("A",T(1,"D","D")), T("D",T(6,7,8)) ),
Dictionary("A",T(1,"D","D"), "D",T(6,7,8)),
T( T("A",T(1,"B","C")), T("C",T(5,"B")), T("B",T(3,4)) ) );
Dictionary("A",T(1,"B","C"), "C",T(5,"B"), "B",T(3,4)) );
foreach ws in (wheelSets){
foreach ws in (wheelSets){
println("Wheel set:");
println("Wheel set:");
ws.pump(String,fcn(w){ " %s: %s\n".fmt(w[0],w[1].concat(" ")) }).print();
ws.pump(String,fcn([(k,v)]){ " %s: %s\n".fmt(k,v.concat(" ")) }).print();
println("-->",intersectingNumberWheelsW(ws.xplode()).walk(20).concat(" "));
println("-->",intersectingNumberWheelsW(ws).walk(20).concat(" "));
}</lang>
}</lang>
{{out}}
{{out}}