Primality by trial division: Difference between revisions

m (syntax highlighting fixup automation)
Line 4,170:
}
}</syntaxhighlight>
 
A version that works with Swift 5.x and probably later. Does not need to import Foundation
 
<syntaxhighlight lang="swift">
extension Int
{
func isPrime() -> Bool
{
if self < 3
{
return self == 2
}
else
{
let upperLimit = Int(Double(self).squareRoot())
return !self.isMultiple(of: 2) && !stride(from: 3, through: upperLimit, by: 2)
.contains(where: { factor in self.isMultiple(of: factor) })
}
}
}
</syntaxhighlight>
 
=={{header|Tcl}}==
19

edits