Legendre prime counting function: Difference between revisions
Content added Content deleted
m (cleanup swift) |
m (Swift: Add missing extension) |
||
Line 768: | Line 768: | ||
<lang swift>import Foundation |
<lang swift>import Foundation |
||
extension Numeric where Self: Strideable { |
|||
@inlinable |
|||
public func power(_ n: Self) -> Self { |
|||
return stride(from: 0, to: n, by: 1).lazy.map({_ in self }).reduce(1, *) |
|||
} |
|||
} |
|||
func eratosthenes(limit: Int) -> [Int] { |
func eratosthenes(limit: Int) -> [Int] { |
||
Line 834: | Line 841: | ||
for i in 0..<10 { |
for i in 0..<10 { |
||
let n = 10. |
let n = 10.power(i) |
||
print("π(10^\(i)) = \(π(n: n))") |
print("π(10^\(i)) = \(π(n: n))") |