Humble numbers: Difference between revisions

Line 842:
(24,29458)
(25,33188)</pre>
 
=={{header|J}}==
Multiply all the humble numbers by all the factors appending the next largest value.
<lang>
humble=: 4 : 0
NB. x humble y generates x humble numbers based on factors y
result=. , 1
while. x > # result do.
a=. , result */ y
result=. result , <./ a #~ a > {: result
end.
)
</lang>
<pre>
p: i.4
2 3 5 7
 
50 humble p: i. 4
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>
 
humbler tests a number for humbleness by deciding if the prime factors are a subset of the given factors.
 
<pre>
humbler=: '' -: (-.~ q:) NB. x humbler y tests whether factors of y are a (improper)subset of x
 
50 {. (#~ (p:i.4)&humbler&>) >: i. 500
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>
 
Use a class to simulate the python generator. This is a more efficient method of the first method.
<lang>
FACTORS_h_=: p: i. 4
HUMBLE_h_=: 1
next_h_=: 3 : 0
result=. <./ HUMBLE
i=. HUMBLE i. result
HUMBLE=: ~. (((i&{.) , (>:i)&}.) HUMBLE) , result * FACTORS
result
)
reset_h_=: 3 :'0 $ HUMBLE=: 1'
</lang>
<pre>
3 :0 [ 50 [ reset_h_''
result=.''
for.i.y do.
result=. result,next_h_''
end.
)
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>
Tally of humble numbers having up to so many digits.
<pre>
H=: 3 :0 [ 40000 [ reset_h_''
result=.''
for.i.y do.
result=. result,next_h_''
end.
)
 
10^.{:H NB. log of tail is number of digits
15.7432
 
(i.16) ,. +/"1 [ (10^i.16) >/ H
0 0
1 9
2 45
3 140
4 337
5 693
6 1272
7 2154
8 3426
9 5193
10 7574
11 10687
12 14671
13 19673
14 25860
15 33405
</pre>
 
=={{header|Java}}==
Anonymous user