Intersecting number wheels: Difference between revisions

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