Intersecting number wheels: Difference between revisions

m
→‎{{header|REXX}}: simplified some code, added/changed whitespace and comments, made functions more idiomatic.
m (→‎Python: Functional composition: Updated primitives, tidied.)
m (→‎{{header|REXX}}: simplified some code, added/changed whitespace and comments, made functions more idiomatic.)
Line 1,953:
@.4= ' A: 1 B C, B: 3 4, C: 5 B '
end
do i=1 while @.i\=''; call buildrun /*construct the wheel set and (gear"execute" sets)it.*/
call run /*execute " " " " " */
end /*i*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
error: procedure; say; say; say '***error***' arg(1); say; say; exit 12
isLet: procedure; parse arg y; return datatype( arg(1)y, 'M') & length( arg(1) y)==1 /*is a letter? */
isNum: procedure; parse arg y; return datatype( arg(1)y, 'N') /*is a number? */
/*──────────────────────────────────────────────────────────────────────────────────────*/
buildrun: @wn= 'wheel name'; first=; @wnnfbacnoColon= '"wheel name not followed by a colon:'"
@gn= 'gear name' ; gear.=; say copies('"'", 79)
say 'building wheel group for: ' @.i; wheels= space(@.i); upper wheels
do y#=1 while wheels\=''; parse var wheels w gears '",'" wheels; L= length(w)
if L==2 then do; !.y#= left(w, 1) /*obtain the 1-charone─character gear name. */
if right(w, 1)\==':' then call error @wnnfbacnoColon w
if \isLet(!.y#) then call error @wn "not a letter:" w
end
else call error "first token isn't a" @wn':' w
if y#==1 then first= !.1 /*Is this is the 1st wheel set? Use it*/
if first=='' then call error "no wheel name was specified."
n= !.y# /*obtain the name of the 1st wheel set.*/
gear.n.0= 1 /*initialize default 1st gear position.*/
say ' setting gear.name:' n ' " gears='" gears
do g=1 for words(gears); _= word(gears, g)
if isNum(_) | isLet(_) then do; gear.n.g= _; iterate; end
call error @gn "isn't a number or a gear name:" _
end /*g*/
end /*y#*/; return
say; say center(' running the wheel named ' first" ", 79, '─'); $=
/*──────────────────────────────────────────────────────────────────────────────────────*/
run: say; saydo center('dummy=0 running theby wheel0 named 'until first" ", 79, "─"words($)==lim; $n= first
do #z= gear.n.0; by 0 until words($) x==lim gear.n.z; nz= firstz + 1
z= gear.n.0; x= gear.n.z; z= z + 1
gear.n.0= z; if gear.n.z=='' then gear.n.0= 1
if isNum(x) then do; $= $ x; iterate; end /*found a number, use it.*/
xx= x /*different gear, keep switching until'til #.X*/
do forever; nn= xx
if gear.nn.0=='' then call error "a gear is using an unknown gear name:" x
zz= gear.nn.0; xx= gear.nn.zz
zz= zz + 1; gear.nn.0= zz; if gear.nn.zz=='' then gear.nn.0= 1
if isNum(xx) then do; $= $ xx; iterate #dummy; end
end /*forever*/ /* [↑] found a number, now use FIRST. */
end /*dummy*/ call run /*execute " DUMMY" is needed "for the " " ITERATE. */
end /*until*/
say '('lim "results): " strip($); say; say; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>