Anonymous user
Lucky and even lucky numbers: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, used templates for the output sections.
m (Minor change in general comment.) |
m (→{{header|REXX}}: added/changed whitespace and comments, used templates for the output sections.) |
||
Line 2,092:
<lang REXX>/*REXX program displays lucky or evenLucky integers (numbers or a number range).*/
parse arg bot top func _ . /*obtain required & optional arguments.*/
if func=='' then func= 'lucky'
s= left('s', bot\==top & top\==",")
say func 'number's":" bot top '───►' $lucky(bot, top, func, _)
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
$lucky: arg x,y,f,?; if y=='' | y=="," then y= x
#= 0; $=;
if f=='' then f= 'LUCKY'; lucky= (f=="LUCKY")
if f\=='LUCKY' & f\=='EVENLUCKY' then return 'function not valid: ' f
if arg()>3 & ?\='' then return "too many arguments entered: " ?
Line 2,107:
if \datatype(y,'W') then return "2nd argument isn't an integer: " y
if x>ay then return "2nd argument is less than 1st arg."
ay=abs(y); yL=ay; if y>0 then yL= y*10
/* [↓] build LUCKY | EVENLUCKY*/
do j=1 until j>=yL /*construct list pos. integers.*/
Line 2,115:
else nop /*balance the IF-THEN logic.*/
else if j //8==0 then iterate /*prune next if mod 8 ≡ zero.*/
#= # +
$= $ j
end /*j*/
q=0
do p=3 until q==''; q= word($, p)
if q># then leave /*if integer is too large, stop*/
do j=#%q*q by -q to q
$= delword($, j, 1)
#= # -1
end /*j*/
end /*p*/
@.=
do k=1; parse var $ q $; if q=='' then leave;
end /*k*/
@.0=k-1
do m=1 for # /*restrict the found integers. */
Line 2,133 ⟶ 2,134:
end /*m*/ /* [↑] a list of #s or a range*/
_=
do b=1 for @.0; _= _ @.b
end /*b*/
return space(_) /*remove superfluous blanks. */</lang>
<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>▼
{{out|output|text= when using the input of: <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>
<pre>
lucky numbers: 6000 -6100 ───► 6009 6019 6031 6049 6055 6061 6079 6093
</pre>
<pre>
evenLucky numbers: 6000 -6100 ───► 6018 6020 6022 6026 6036 6038 6050 6058 6074 6090 6092
</pre>
<pre>
lucky number: 10000 ───► 115591
</pre>
▲'''output''' when the input is: <tt> 10000 , evenLucky </tt>
▲
<pre>
evenLucky number: 10000 ───► 111842
|