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(1e51e7-1)
 
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 break{
next = next.min(prod)
i = (k == 1) ? i + 1: i + 2 break
}
}
}
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..912) {
var limit = 10.pow(k)
var totalres = getBrilliant.call(k, limit, true)
var itotal = (k == 1) ? limit : limit + 1res[0]
whilevar (true)next {= res[1]
Fmt.print("First >= $,13d17d is $,11r15r in the series: $,13d17d", limit, total + 1, inext)
var factors = Int.primeFactors(i)
if (factors.count == 2) {
if (factors[0].toString.count == factors[1].toString.count) break
}
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>
 
9,482

edits