Lucky and even lucky numbers: Difference between revisions

added RPL
m (→‎{{header|Wren}}: Minor tidy)
(added RPL)
 
Line 2,900:
[6018, 6020, 6022, 6026, 6036, 6038, 6050, 6058, 6074, 6090, 6092]
</pre>
 
=={{header|RPL}}==
{{works with|HP|48}}
The program returns even lucky numbers when one of the 2 arguments is negative, which is more idiomatic.
{| class="wikitable" ≪
! RPL code
! Comment
|-
|
1 CF DUP2 * 0 < ≪ 1 SF ≫ IFT
ABS SWAP ABS DUP2 ≤ ≪ #202h DOERR ≫ IFT
2 → b a n
≪ { } 1 1 FS? + b '''FOR''' j j + 2 '''STEP'''
'''DO'''
DUP n GET → m
≪ { } 1 3 PICK SIZE '''FOR''' j
OVER j DUP m + 2 - SUB + m '''STEP'''
≫ SWAP DROP 'n' INCR
'''UNTIL''' OVER SIZE > '''END'''
{ } 1 3 PICK SIZE '''FOR''' j
'''IF''' OVER j GET DUP a < '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT''' SWAP DROP
≫ ≫ '<span style="color:blue">LUCKY</span>' STO
|
<span style="color:blue">LUCKY</span> ''( a (-)b → { (even)lucky } )''
Set flag 1 if a xor b is negative
abort if b ≤ a with an error message
n = 2
generate list of odd/even numbers according to flag 1
loop
m = nth number of the list
for j = 1 to size(list) step m
keep numbers from j to j+m-2
clean stack ; n++
until n > size(list)
for j = 1 to size(list)
keep jth number only if ≥ a
clean stack
return list
|}
1 80 <span style="color:blue">LUCKY</span>
1 -80 <span style="color:blue">LUCKY</span>
6000 6100 <span style="color:blue">LUCKY</span>
6000 -6100 <span style="color:blue">LUCKY</span>
{{out}}
<pre>
4: { 1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 }
3: { 2 4 6 10 12 18 20 22 26 34 36 42 44 50 52 54 58 68 70 76 }
2: { 6009 6019 6031 6049 6055 6061 6079 6093 }
1: { 6018 6020 6022 6026 6036 6038 6050 6058 6074 6090 6092 }
</pre>
A 6000-number sieve requiring more than 30 KB RAM, the last 2 demonstrations have been run on an emulator instead of a genuine calculator.
 
 
=={{header|Ruby}}==
1,151

edits