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.139 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.138 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.137 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.136 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.135 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.134 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.133 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.132 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.131 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.130 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.129 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.128 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.127 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.126 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.125 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.124 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.123 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.122 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.121 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.120 tracks/fsharp/exercises/nth-prime/Example.fs