Intersecting number wheels: Difference between revisions

no edit summary
(Java edit)
No edit summary
Line 1,082:
</pre>
 
=={{header|Maple}}==
 
<lang Maple>
with(ArrayTools):
 
module Wheel()
option object;
local spokes := Array([1,2,3]);
local currentSpoke := 1;
 
export currentValue::static := proc(self::Wheel)
local valueOut;
if type(self:-spokes[self:-currentSpoke], integer) then
valueOut := self:-spokes[self:-currentSpoke]:
else
valueOut := currentValue(self:-spokes[self:-currentSpoke]):
end if:
rotate(self):
return valueOut;
end proc:
 
export rotate::static := proc(self::Wheel)
if self:-currentSpoke = ArrayNumElems(self:-spokes) then self:-currentSpoke := 1:
else self:-currentSpoke += 1: end if:
end proc:
 
export ModuleApply::static := proc()
Object(Wheel, _passed);
end proc:
 
export ModuleCopy::static := proc(new::Wheel, proto::Wheel, spo::Array, curr::integer, $)
new:-spokes := spo:
new:-currentSpoke := curr:
end proc:
end module:
 
A := Wheel(Array([1,2,3]), 1):
 
seq(currentValue(A), 1..20);
 
A := Wheel(Array([1,B,2]), 1):
B := Wheel(Array([3,4]), 1):
 
seq(currentValue(A), 1..20);
 
A := Wheel(Array([1,d,d]), 1):
d := Wheel(Array([6,7,8]), 1):
 
seq(currentValue(A), 1..20);
 
A := Wheel(Array([1,b,C]), 1):
b := Wheel(Array([3,4]), 1):
C := Wheel(Array([5,b]), 1):
 
seq(currentValue(A), 1..20);
</lang>
 
{{out}}<pre>
1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2
 
1, 3, 2, 1, 4, 2, 1, 3, 2, 1, 4, 2, 1, 3, 2, 1, 4, 2, 1, 3
 
1, 6, 7, 1, 8, 6, 1, 7, 8, 1, 6, 7, 1, 8, 6, 1, 7, 8, 1, 6
 
1, 3, 5, 1, 4, 3, 1, 4, 5, 1, 3, 4, 1, 3, 5, 1, 4, 3, 1, 4
 
</pre>
=={{header|Perl}}==
{{trans|Julia}}
Anonymous user