Intersecting number wheels: Difference between revisions
Content added Content deleted
Alpha bravo (talk | contribs) (Added AutoHotkey) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 2,151: | Line 2,151: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
<lang ruby>groups = [{A: [1, 2, 3]}, |
|||
{A: [1, :B, 2], B: [3, 4]}, |
|||
{A: [1, :D, :D], D: [6, 7, 8]}, |
|||
{A: [1, :B, :C], B: [3, 4], C: [5, :B]} ] |
|||
groups.each do |group| |
|||
p group |
|||
wheels = group.transform_values(&:cycle) |
|||
res = 20.times.map do |
|||
el = wheels[:A].next |
|||
el = wheels[el].next until el.is_a?(Integer) |
|||
el |
|||
end |
|||
puts res.join(" "),"" |
|||
end |
|||
</lang> |
|||
{{out}} |
|||
<pre>{:A=>[1, 2, 3]} |
|||
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 |
|||
{:A=>[1, :B, 2], :B=>[3, 4]} |
|||
1 3 2 1 4 2 1 3 2 1 4 2 1 3 2 1 4 2 1 3 |
|||
{:A=>[1, :D, :D], :D=>[6, 7, 8]} |
|||
1 6 7 1 8 6 1 7 8 1 6 7 1 8 6 1 7 8 1 6 |
|||
{:A=>[1, :B, :C], :B=>[3, 4], :C=>[5, :B]} |
|||
1 3 5 1 4 3 1 4 5 1 3 4 1 3 5 1 4 3 1 4 |
|||
</pre> |
|||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
{{trans|C#}} |
{{trans|C#}} |