Multi-base primes: Difference between revisions
→{{header|Wren}}: Much improved - more than 10 times quicker than before.
m (Minor edit to Rust code) |
(→{{header|Wren}}: Much improved - more than 10 times quicker than before.) |
||
Line 270:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int, Nums
import "/fmt" for Conv
var maxDepth = 5
var c = Int.primeSieve(36.pow(
var digits = Conv.digits // all digits up to base 36
var maxStrings = []
var mostBases = -1
var
if (b > min) min = b▼
}▼
var bases = []
for (b in
}
var count = bases.count
if (count > mostBases) {
mostBases = count
maxStrings = [[
} else if (count == mostBases) {
maxStrings.add([
}
}
Line 305 ⟶ 299:
var printResults = Fn.new {
System.print("%(maxStrings[0][1].count)")
for (
System.print("%(s) -> %(m[1])")
}
}
var nestedFor // recursive
System.write("1 character strings which are prime in most bases: ")▼
nestedFor = Fn.new { |indices, length, level|
for (s in digits) process.call(s)▼
if (level == indices.count) {
printResults.call()▼
▲ } else {
System.write("\n2 character strings which are prime in most bases: ")▼
indices[level] = (level == 0) ? 1 : 0
maxStrings = []▼
while (indices[level] < length) {
mostBases = -1▼
nestedFor.call(indices, length, level + 1)
indices[level] = indices[level] + 1
▲ for (d3 in digits) {
}
}
}
for (depth in 1..maxDepth) {
▲ maxStrings = []
▲ mostBases = -1
var indices = List.filled(depth, 0)
nestedFor.call(indices, digits.count, 0)
▲ printResults.call()
System.print()
}</lang>
{{out}}
Line 369 ⟶ 344:
1727 -> [8, 9, 11, 12, 13, 15, 16, 17, 19, 20, 22, 23, 24, 26, 27, 29, 31, 33, 36]
5347 -> [8, 9, 10, 11, 12, 13, 16, 18, 19, 22, 24, 25, 26, 30, 31, 32, 33, 34, 36]
30271 -> [8, 10, 12, 13, 16, 17, 18, 20, 21, 23, 24, 25, 31, 32, 33, 34, 35, 36]
</pre>
|