Sha256: b399b9d5c08b6efb06c898b74ee5caead113f10b1340c632a270333669804127

Contents?: true

Size: 551 Bytes

Versions: 131

Compression:

Stored size: 551 Bytes

Contents

module NthPrime

open System

let isPrime (n: int) = 
    let r = Math.Floor(Math.Sqrt(n |> double)) |> int
    r < 5 || Seq.init (r - 4) id |> Seq.forall (fun x -> n % (5 + x) <> 0)

let rec possiblePrimes n = 
    seq { 
        yield n - 1
        yield n + 1
        yield! possiblePrimes (n + 6)
    }
    
let primes = 
    seq {
        yield 2
        yield 3
        yield! Seq.filter isPrime (possiblePrimes 6)
    }

let prime nth : int option = 
    match nth with 
    | n when n < 1 -> None
    | _ -> Some (Seq.item (nth - 1) primes)

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/nth-prime/Example.fs