Achilles numbers: Difference between revisions
m
→Version 2 (Much faster): Timing correction and other minor changes.
(→Version 2 (Much faster): Oops.) |
m (→Version 2 (Much faster): Timing correction and other minor changes.) |
||
Line 492:
Here we make use of the fact that powerful numbers are always of the form a²b³, where a and b > 0, to generate such numbers up to a given limit. We also use an improved method for checking whether a number is a perfect power.
Ridiculously fast compared to the previous method: 8 digits now reached in 0.57 seconds, 9 digits in 4.
<lang ecmascript>import "./set" for Set, Bag
import "./math" for Int
Line 522:
}
var getAchilles = Fn.new { |
var
var upper = 10.pow(maxDigits)
var achilles = Set.new() // avoids duplicates
var count = 0
Line 539 ⟶ 540:
}
var achillesSet = getAchilles.call(
var achilles = achillesSet.toList
achilles.sort()
Line 563 ⟶ 564:
System.print("\nNumber of Achilles numbers with:")
for (d in 2..maxDigits) {
var ac = getAchilles.call(d-1,
Fmt.print("$2d digits: $d", d, ac)
}</lang>
|