Generator/Exponential: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: deleted a superflous blank lines. -- ~~~~)
m (→‎{{header|REXX}}: added whitespace, change output gylphs. -- ~~~~)
Line 1,425: Line 1,425:
/*how_many: show that many vals.*/
/*how_many: show that many vals.*/
parse arg how_many; how_many=pick1(how_many 0)
parse arg how_many; how_many=pick1(how_many 0)

do j=1 for how_many; call tell 'squares' ,gen_squares(j) ; end
do j=1 for how_many; call tell 'cubes' ,gen_cubes(j) ; end
do j=1 to how_many; call tell 'squares' ,gen_squares(j) ; end
do j=1 for how_many; call tell 'sq¬cubes',gen_sqNcubes(j) ; end
do j=1 to how_many; call tell 'cubes' ,gen_cubes(j) ; end
do j=1 to how_many; call tell 'sq¬cubes',gen_sqNcubes(j) ; end
if how_many>0 then say 'dropping 1st --> 20th values.'
if how_many>0 then say 'dropping 1st ──► 20th values.'
do j=1 for 20; drop gen_.sqNcubes.j ; end
do j=20+1 for 10 ; call tell 'sq¬cubes',gen_sqNcubes(j) ; end
do j=1 to 20; drop gen_.sqNcubes.j ; end
do j=20+1 for 10 ; call tell 'sq¬cubes',gen_sqNcubes(j) ; end
exit

exit /*stick a fork in it, we're done.*/

/*─────────────────────────────────────generate powers iterator─────────*/
/*─────────────────────────────────────generate powers iterator─────────*/
gen_powers: procedure expose gen_.; parse arg x,p; if x=='' then return
gen_powers: procedure expose gen_.; parse arg x,p; if x=='' then return
if gen_.powers.x.p=='' then gen_.powers.x.p=x**p
if gen_.powers.x.p=='' then gen_.powers.x.p=x**p
return gen_.powers.x.p
return gen_.powers.x.p

/*─────────────────────────────────────gen squares iterator─────────────*/
/*─────────────────────────────────────gen squares iterator─────────────*/
gen_squares: procedure expose gen_.; parse arg x;if x=='' then return
gen_squares: procedure expose gen_.; parse arg x; if x=='' then return
if gen_.squares.x=='' then do
if gen_.squares.x=='' then do
call gen_powers x,2
call gen_powers x,2
Line 1,443: Line 1,447:
end
end
return gen_.squares.x
return gen_.squares.x

/*─────────────────────────────────────gen cubes iterator───────────────*/
/*─────────────────────────────────────gen cubes iterator───────────────*/
gen_cubes: procedure expose gen_.; parse arg x; if x=='' then return
gen_cubes: procedure expose gen_.; parse arg x; if x=='' then return
if gen_.cubes.j=='' then do
if gen_.cubes.j=='' then do
call gen_powers x,3
call gen_powers x,3
Line 1,450: Line 1,455:
end
end
return gen_.cubes.x
return gen_.cubes.x

/*─────────────────────────────────────gen squares not cubes iterator───*/
/*─────────────────────────────────────gen squares not cubes iterator───*/
gen_sqNcubes: procedure expose gen_.; parse arg x; if x=='' then return
gen_sqNcubes: procedure expose gen_.; parse arg x; if x=='' then return
s=1
s=1
if gen_.sqNcubes.x=='' then do j=1 to x
if gen_.sqNcubes.x=='' then do j=1 to x
Line 1,469: Line 1,475:
end /*j*/
end /*j*/
return gen_.sqNcubes.x
return gen_.sqNcubes.x

/*─────────────────────────────────────"1─liner" subroutines────────────*/
/*─────────────────────────────────────"1─liner" subroutines────────────*/
tell: if j==1 then say /*format args to be aligned up. */
tell: if j==1 then say /*format args to be aligned up. */
say right(arg(1),20) right(j,5) right(arg(2),20); return
say right(arg(1),20) right(j,5) right(arg(2),20); return

pick1: return word(arg(1) arg(2),1)</lang>
pick1: return word(arg(1) arg(2),1)</lang>
'''output''' when using the default (no input)
'''output''' when using the default (no input)
Line 1,520: Line 1,528:
sq¬cubes 9 121
sq¬cubes 9 121
sq¬cubes 10 144
sq¬cubes 10 144
dropping 1st --> 20th values.
dropping 1st ──► 20th values.
sq¬cubes 21 529
sq¬cubes 21 529
sq¬cubes 22 576
sq¬cubes 22 576