Increasing gaps between consecutive Niven numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: better idiom)
(julia example)
Line 133: Line 133:
276 1,039,028,518 18,879,988,824
276 1,039,028,518 18,879,988,824
</pre>
</pre>


=={{header|Julia}}==
lang julia>using Formatting

function findharshadgaps(N)
isharshad(i) = i % sum(digits(i)) == 0
println("Gap Index Number Index Niven Number")
lastnum, lastnumidx, biggestgap = 1, 1, 0
for i in 2:N
if isharshad(i)
if (gap = i - lastnum) > biggestgap
println(lpad(gap, 5), lpad(format(lastnumidx, commas=true), 14),
lpad(format(lastnum, commas=true), 18))
biggestgap = gap
end
lastnum, lastnumidx = i, lastnumidx + 1
end
end
end

findharshadgaps(50_000_000_000)
</lang>{{out}}
<pre>
Gap Index Number Index Niven Number
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
135 44,194,186 689,988,915
144 55,065,654 879,987,906
150 61,074,615 989,888,823
153 179,838,772 2,998,895,823
192 399,977,785 6,998,899,824
201 497,993,710 8,889,999,624
234 502,602,764 8,988,988,866
258 547,594,831 9,879,997,824
276 1,039,028,518 18,879,988,824
</pre>



=={{header|Perl 6}}==
=={{header|Perl 6}}==