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' /*Not specified? Then use the default.*/
s= left('s', bot\==top & top\==",") /*plural results (or maybe not plural).*/
say func 'number's":" bot top '───►' $lucky(bot, top, func, _)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
$lucky: arg x,y,f,?; if y=='' | y=="," then y= x /*obtain some arguments; set Y.*/
#= 0; $=; ny=y<0 ny= y<0 /*set variable NOY: value range*/
if f=='' then f= 'LUCKY'; lucky= (f=="LUCKY") /*assume LUCKY if omitted. */
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+y+y + y + y /*adjust the upper Y limit. */
/* [↓] 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.*/
#= # +1 1 /*bump the counter of numbers. */
$= $ j /*append integer to the $ list.*/
end /*j*/
q=0
do p=3 until q==''; q= word($, p) /*start to prune integer list.*/
if q># then leave /*if integer is too large, stop*/
do j=#%q*q by -q to q /*elide every Qth integer. */
$= delword($, j, 1) /*delete a particular number. */
#= # -1 /*decrease the integer count. */
end /*j*/ /*delete from the right side. */
end /*p*/
@.=
do k=1; parse var $ q $; if q=='' then leave; @.k=q; end /* @.k*/= q
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*/ /*construct a list of integers.*/
end /*b*/
return space(_) /*remove superfluous blanks. */</lang>
'''{{out|output''' |text=&nbsp; when using the input isof: &nbsp; &nbsp; <tt> 1 &nbsp; 20 &nbsp; 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''' &nbsp; when the input is: &nbsp; <tt> 1 &nbsp; 20 &nbsp; evenLucky </tt>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 1 &nbsp; 20 &nbsp; 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>
 
'''{{out|output''' |text=&nbsp; when using the input isof: &nbsp; &nbsp; <tt> 6000 &nbsp; -6100 &nbsp; lucky </tt>}}
<pre>
lucky numbers: 6000 -6100 ───► 6009 6019 6031 6049 6055 6061 6079 6093
</pre>
 
'''{{out|output''' |text=&nbsp; when using the input isof: &nbsp; &nbsp; <tt> 6000 &nbsp; -6100 &nbsp; venLuckyevenLucky </tt>}}
<pre>
evenLucky numbers: 6000 -6100 ───► 6018 6020 6022 6026 6036 6038 6050 6058 6074 6090 6092
</pre>
 
'''{{out|output''' |text=&nbsp; when using the input isof: &nbsp; &nbsp; <tt> 10000 </tt>}}
<pre>
lucky number: 10000 ───► 115591
</pre>
 
'''output''' &nbsp; when the input is: &nbsp; <tt> 10000 &nbsp; , &nbsp; evenLucky </tt>
'''{{out|output''' |text=&nbsp; when using the input isof: &nbsp; &nbsp; <tt> 110000 &nbsp; 20, &nbsp; evenLucky </tt>}}
<pre>
evenLucky number: 10000 ───► 111842