Brilliant numbers: Difference between revisions
→{{header|Wren}}: Much quicker than before.
m (→{{header|Phix}}: less significant 2-fold speedup, binary chop instead of +1, --> 1e13, removed trans Wren, since it really ain't no more.) |
(→{{header|Wren}}: Much quicker than before.) |
||
Line 486:
import "./fmt" for Fmt
var primes = Int.primeSieve(
var getBrilliant = Fn.new { |digits, limit, countOnly|
Line 492:
var count = 0
var pow = 1
var next = Num.maxSafeInteger
for (k in 1..digits) {
var s = primes.where { |p| p > pow && p < pow * 10 }.toList
Line 503 ⟶ 504:
brilliant.add(prod)
}
} else
next = next.min(prod)
}▼
}
}
pow = pow * 10
}
return countOnly ? [count, next] : [brilliant, next]
}
System.print("First 100 brilliant numbers:")
var brilliant = getBrilliant.call(2, 10000, false)[0]
brilliant.sort()
brilliant = brilliant[0..99]
for (chunk in Lst.chunks(brilliant, 10)) Fmt.print("$4d", chunk)
System.print()
for (k in 1..
var limit = 10.pow(k)
var
var
▲ }
▲ i = (k == 1) ? i + 1: i + 2
▲ Fmt.print("First >= $,13d is $,11r in the series: $,13d", limit, total + 1, i)
}</lang>
Line 545 ⟶ 543:
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369
First >= 10 is 4th in the series: 10
First >= 100 is 11th in the series: 121
First >= 1,000 is 74th in the series: 1,003
First >= 10,000 is 242nd in the series: 10,201
First >= 100,000 is 2,505th in the series: 100,013
First >= 1,000,000 is 10,538th in the series: 1,018,081
First >= 10,000,000 is 124,364th in the series: 10,000,043
First >= 100,000,000 is 573,929th in the series: 100,140,049
First >= 1,000,000,000 is 7,407,841st in the series: 1,000,000,081
First >= 10,000,000,000 is 35,547,995th in the series: 10,000,600,009
First >= 100,000,000,000 is 491,316,167th in the series: 100,000,000,147
First >= 1,000,000,000,000 is 2,409,600,866th in the series: 1,000,006,000,009
</pre>
|