Increasing gaps between consecutive Niven numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added zkl header) |
(→{{header|zkl}}: added code) |
||
Line 246: | Line 246: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
<lang zkl>harshadW:=[1..].tweak(fcn(n){ if(n%(n.split().sum(0))) Void.Skip else n }); |
|||
⚫ | |||
harshadW:=Walker.zero().tweak(fcn(go){ // faster than one liner, fewer calls |
|||
<lang zkl></lang> |
|||
foreach h in ([go.value..]){ // spin |
|||
s,t := 0,h; while(t){ s+=t%10; t/=10 } // sum of digits |
|||
if(0 == h%s){ go.set(h+1); return(h) } |
|||
} |
|||
}.fp(Ref(1)));</lang> |
|||
<lang zkl>println("gap size Niven index Niven #"); |
|||
prev,gap := harshadW.next(),0; |
|||
while(harshadW.n<=10_000_000){ |
|||
if( (g:=(h:=harshadW.next()) - prev) > gap){ |
|||
println("%5,d %14,d %15,d".fmt(g, harshadW.n - 1, prev)); |
|||
gap=g; |
|||
} |
|||
prev=h; |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
gap size Niven index Niven # |
|||
1 1 1 |
|||
2 10 10 |
|||
6 11 12 |
|||
7 26 63 |
|||
8 28 72 |
|||
10 32 90 |
|||
12 83 288 |
|||
14 102 378 |
|||
18 143 558 |
|||
23 561 2,889 |
|||
32 716 3,784 |
|||
36 1,118 6,480 |
|||
44 2,948 19,872 |
|||
45 4,194 28,971 |
|||
54 5,439 38,772 |
|||
60 33,494 297,864 |
|||
66 51,544 478,764 |
|||
72 61,588 589,860 |
|||
88 94,748 989,867 |
|||
90 265,336 2,879,865 |
|||
99 800,054 9,898,956 |
|||
108 3,750,017 49,989,744 |
|||
126 6,292,149 88,996,914 |
|||
</pre> |
</pre> |