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( |
<lang zkl>fcn intersectingNumberWheelsW(wheels){ // ("A":(a,b,"C"), "C":(d,e) ...) |
||
ws:= |
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( |
<lang zkl>wheelSets:=T( Dictionary("A",T(1,2,3)), |
||
Dictionary("A",T(1,"B",2), "B",T(3,4)), |
|||
Dictionary("A",T(1,"D","D"), "D",T(6,7,8)), |
|||
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( |
ws.pump(String,fcn([(k,v)]){ " %s: %s\n".fmt(k,v.concat(" ")) }).print(); |
||
println("-->",intersectingNumberWheelsW(ws |
println("-->",intersectingNumberWheelsW(ws).walk(20).concat(" ")); |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |