RosettaCodeData/Task/Intersecting-number-wheels/Maple/intersecting-number-wheels.maple
2023-07-01 13:44:08 -04:00

52 lines
1.2 KiB
Text

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);