PONS, Protocol-Oriented Number System in Pure Swift.
It has all functionality of swift-prime plus BigInt
support.
Prime number extension in Pure Swift
import Prime // not needed if you are using prime.swift directly
2.isPrime // true
42.isPrime // false
0x7FFFffff.isPrime // true (M31)
0.nextPrime // 2
Int.max.prevPrime // 9223372036854775783 on OS X
Int.Prime.within(0..<100) // [2, 3, 5, 7, ... 97]
Int.Prime.within(Int.max-100..<Int.max) // [9223372036854775783]
Int.max.primeFactors // [7, 7, 73, 127, 337, 92737, 649657]
Swift 2.x, both Xcode 7 and Linux.
- It emits warings on Swift 2.2 but works okay.
Just add prime.swift to it.
Browse all the playgrounds and the project via Prime.xcworkspace
.
Just open the playground file of your OS of choice and enjoy. OSX most detaild. iOS and tvOS just for testing purpurse.
just make repl
.
1> 42.isPrime
repl.swift:1:1: error: value of type 'Int' has no member 'isPrime'
42.isPrime
^~ ~~~~~~~
1> import Prime
2> 42.isPrime
$R0: Bool = false
3>
git clone https://github.com/dankogai/swift-prime.git
cd swift-prime
make repl
git clone https://github.com/dankogai/swift-prime.git
cd swift-prime
make SWIFTPATH=${YOUR_SWIFT_PATH} repl # ${YOUR_SWIFT_PATH}=~/swift/usr/bin in my case
It used to depend on 128-bit arithmetics bridged to C but it is written to be C-Free. In exchange it is a little slower.