Increasing gaps between consecutive Niven numbers: Difference between revisions

Content added Content deleted
m (Minor performance improvement)
(Added Wren)
Line 1,014: Line 1,014:
tell: say arg(1); return</lang>
tell: say arg(1); return</lang>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br> !-->
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br> !-->

=={{header|Wren}}==
{{trans|Go}}
{{libheader|fmt}}
Limited to Niven numbers below 1 billion in order to finish in a reasonable time (a little under 2 minutes on my machine).
<lang ecmascript>import "/fmt" for Fmt

var newSum // recursive
newSum = Fn.new {
var ms // also recursive
ms = Fn.new {
ms = newSum.call()
return ms.call()
}
var msd = 0
var d = 0
return Fn.new {
if (d < 9) {
d = d + 1
} else {
d = 0
msd = ms.call()
}
return msd + d
}
}

var newHarshard = Fn.new {
var i = 0
var sum = newSum.call()
return Fn.new {
i = i + 1
while (i%sum.call() != 0) i = i + 1
return i
}
}

System.print("Gap Index of gap Starting Niven")
System.print("=== ============= ==============")
var h = newHarshard.call()
var pg = 0 // previous highest gap
var pn = h.call() // previous Niven number
var i = 1
var n = h.call()
while (n <= 1e9) {
var g = n - pn
if (g > pg) {
System.print("%(Fmt.d(3, g)) %(Fmt.dc(13, i)) %(Fmt.dc(14, pn))")
pg = g
}
pn = n
i = i + 1
n = h.call()
}</lang>

{{out}}
<pre>
Gap Index of gap Starting 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
135 44,194,186 689,988,915
144 55,065,654 879,987,906
150 61,074,615 989,888,823
</pre>


=={{header|zkl}}==
=={{header|zkl}}==