Anonymous user
Generator/Exponential: Difference between revisions
m
→{{header|REXX}}: aligned and changed some comments and statements.
m (→{{header|REXX}}: simplified a function.) |
m (→{{header|REXX}}: aligned and changed some comments and statements.) |
||
Line 1,851:
<lang rexx>/*REXX program demonstrates how to use a generator (also known as iterators).*/
parse arg N .; if N=='' then N=20 /*N not specified? Then use default.*/
@.= /*
do j=1 for N; call Gsquare
call Gcube
call GpureSquare
end /*j*/
do k=1 for N; @.pureSquare.k=; end /*k*/
w=length(N+10); ps='pure square'
do m=N+1 for 10; say ps
end /*m*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
Gpower: procedure expose @.; parse arg x,p;
if q\=='' then return q; _=x**p
if pos(.,_)\==0 then do
Line 1,873:
return _
/*────────────────────────────────────────────────────────────────────────────*/
Gsquare: procedure expose @.; parse arg x;
if q=='' then @.square.x=Gpower(x,2)
return @.square.x
/*────────────────────────────────────────────────────────────────────────────*/
Gcube: procedure expose @.; parse arg x; q=@.cube.x
if q=='' then @.cube.x=Gpower(x,3); _=@.cube.x; @.3pow._=1
return @.cube.x
/*────────────────────────────────────────────────────────────────────────────*/
GpureSquare: procedure expose @.; parse arg x;
if q\=='' then
#=0
do j=1 until #==x; ?=Gpower(j,2)
if @.3pow.?==1 then iterate
#=#+1; @.pureSquare.#=?
end /*j*/
return @.pureSquare.x</lang>
|