Intersecting number wheels: Difference between revisions
Content added Content deleted
(New draft task with python example.) |
(julia example) |
||
Line 59: | Line 59: | ||
Show your output here, on this page. |
Show your output here, on this page. |
||
=={{header|Julia}}== |
|||
<lang julia>const d1 = Dict("A" => [["1", "2", "3"], 1]) |
|||
const d2 = Dict("A" => [["1", "B", "2"], 1], "B" => [["3", "4"], 1]) |
|||
const d3 = Dict("A" => [["1", "D", "D"], 1], "D" => [["6", "7", "8"], 1]) |
|||
const d4 = Dict("A" => [["1", "B", "C"], 1], "B" => [["3", "4"], 1], |
|||
"C" => [["5", "B"], 1]) |
|||
function getvalue(wheelname, allwheels) |
|||
wheel = allwheels[wheelname] |
|||
s = wheel[1][wheel[2]] |
|||
wheel[2] = mod1(wheel[2] + 1, length(wheel[1])) |
|||
return haskey(allwheels, s) ? getvalue(s, allwheels) : s |
|||
end |
|||
function testwheels(wheels, numterms = 20, firstwheel = "A") |
|||
println("\nNumber Wheels:") |
|||
for k in sort(collect(keys(wheels))) |
|||
print("$k: [") |
|||
for s in wheels[k][1] |
|||
print(s, " ") |
|||
end |
|||
println("\b]") |
|||
end |
|||
print("Output: ") |
|||
for _ in 1:numterms |
|||
print(getvalue(firstwheel, wheels), " ") |
|||
end |
|||
println("...") |
|||
end |
|||
foreach(testwheels, [d1, d2, d3, d4]) |
|||
</lang>{{out}} |
|||
<pre> |
|||
Number Wheels: |
|||
A: [1 2 3] |
|||
Output: 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 ... |
|||
Number Wheels: |
|||
A: [1 B 2] |
|||
B: [3 4] |
|||
Output: 1 3 2 1 4 2 1 3 2 1 4 2 1 3 2 1 4 2 1 3 ... |
|||
Number Wheels: |
|||
A: [1 D D] |
|||
D: [6 7 8] |
|||
Output: 1 6 7 1 8 6 1 7 8 1 6 7 1 8 6 1 7 8 1 6 ... |
|||
Number Wheels: |
|||
A: [1 B C] |
|||
B: [3 4] |
|||
C: [5 B] |
|||
Output: 1 3 5 1 4 3 1 4 5 1 3 4 1 3 5 1 4 3 1 4 ... |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |