Jump to content

Humble numbers: Difference between revisions

add RPL
(→‎{{header|F_Sharp|F#}}: add faster implementations at the end...)
(add RPL)
Line 6,065:
The first 50 Humble numbers:
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120
</pre>
 
=={{header|RPL}}==
Brute force is summoned to generate the list of the first humble numbers, but direct humble numbers generation and immediate digit counting allow to obtain the distribution of humble numbers below a user-defined value in a few seconds with an emulator, requiring a few stack levels and a vector sized at the maximum number of digits only.
 
On a 4-bit calculator with 32 Mb RAM, it takes 25 seconds to get the first 50 numbers and 9 minutes to count all the humble numbers under 1,000,000
{{works with|HP|48}}
≪ '''CASE'''
DUP 1 == '''THEN END'''
DUP 2 MOD NOT '''THEN''' 2 / <span style="color:blue>H?</span> '''END'''
DUP 3 MOD NOT '''THEN''' 3 / <span style="color:blue>H?</span> '''END'''
DUP 5 MOD NOT '''THEN''' 5 / <span style="color:blue>H?</span> '''END'''
DUP 7 MOD NOT '''THEN''' 7 / <span style="color:blue>H?</span> '''END'''
NOT '''END'''
≫ '<span style="color:blue>H?</span>' STO
≪ { } 0 → j
≪ '''WHILE''' DUP2 SIZE > '''REPEAT'''
'j' INCR
'''IF''' <span style="color:blue>H?</span> '''THEN''' j + '''END'''
'''END''' SWAP DROP
≫ ≫ '<span style="color:blue>HLIST</span>' STO
 
{{works with|HP|28}}
≪ 1 4 '''FOR''' j
DUP LN { 2 3 5 7 } j GET LN / CEIL SWAP '''NEXT''' <span style="color:grey>@ max exponent for n factor is ceil(log(max value)/log(n))</span>
DUP LOG CEIL { } + 0 CON <span style="color:grey>@ create vector of counters</span>
→ m2 m3 m5 m7 max cnt
≪ 1
0 m2 '''FOR''' j
j 2 1 IFTE * DUP
0 m3 '''FOR''' k
k 3 1 IFTE * DUP
0 m5 '''FOR''' m
m 5 1 IFTE * DUP
0 m7 '''FOR''' n
n 7 1 IFTE *
'''IF''' DUP max ≤ '''THEN'''
cnt OVER XPON 1 + DUP2 GET 1 + PUT 'cnt' STO
'''ELSE''' m7 'n' STO '''END''' <span style="color:grey>@ only way to break a FOR..NEXT loop in RPL</span>
'''NEXT''' DROP
'''NEXT''' DROP
'''NEXT''' DROP
'''NEXT''' DROP
cnt
≫ ≫ '<span style="color:blue>HCNT</span>' STO
 
50 <span style="color:blue>HLIST</span>
999999999999 <span style="color:blue>HCNT</span>
{{out}}
<pre>
2: { 1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120 }
1: [ 9 36 95 197 356 579 882 1272 1767 2381 3113 3984 ]
</pre>
 
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.