Anonymous user
Lucky and even lucky numbers: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations.
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
|||
Line 453:
=={{header|REXX}}==
This REXX version does extra error checking for the arguments.
<lang REXX>/*REXX program displays lucky or evenLucky integers (
if func=='' then func='lucky' /*Not specified? Then use the default.*/
say func 'number's":" bot top '───►' $lucky(bot, top, func, _)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
#=0; $=; ny=y<0 /*set variable NOY: value range*/
if f
if x
if
if \datatype(
if x>ay then return "2nd argument is less than 1st arg."
ay=abs(y); yL=ay; if y>0 then yL=y*10+y+y /*adjust the upper Y limit. */
/* [↓] build
do j=1 until j>=yL /*construct list
if j//2==(\lucky) then iterate /*EVENLUCKY?
if lucky then if (j+1)//6==0 then iterate /*prune if mod
else nop /*balance the IF-THEN logic.
else if j //8==0 then iterate /*prune next if mod
#=#+1 /*bump the counter of
$=$ j /*append integer to the
end /*j*/
q=0
do p=3 until
if
do j=#%
$=delword($, j, 1)
#=#-1 /*decrease the integer count. */
end /*j*/ /*delete from the right
end /*p*/
@.=
do k=1; parse var $ q $; if q=='' then leave; @.k=q; end /*k*/
@.0=k-1
do
if (\ny & (
end /*
_=
return space(_) /*remove superfluous
'''output''' when the input is: <tt> 1 20 lucky </tt>
<pre>
lucky numbers: 1 20 ───► 1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79
</pre>
'''output''' when the input is: <tt> 1 20 evenLucky </tt>
<pre>
evenLucky numbers: 1 20 ───► 2 4 6 10 12 18 20 22 26 34 36 42 44 50 52 54 58 68 70 76
</pre>
'''output''' when the input is: <tt> 6000 -6100 lucky</tt>
<pre>
lucky numbers: 6000 -6100 ───► 6009 6019 6031 6049 6055 6061 6079 6093
</pre>
'''output''' when the input is: <tt> 6000 -6100
<pre>
evenLucky numbers: 6000 -6100 ───► 6018 6020 6022 6026 6036 6038 6050 6058 6074 6090 6092
</pre>
'''output''' when the input is: <tt> 10000 </tt>
<pre>
lucky number: 10000 ───► 115591
</pre>
'''output''' when the input is: <tt> 10000 , evenLucky </tt>
<pre>
evenLucky number: 10000 ───► 111842
|