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.78 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.77 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.76 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.75 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.74 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.73 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.72 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.71 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.70 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.69 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.68 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.67 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.66 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.65 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.64 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.63 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.62 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.61 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.60 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.59 tracks/fsharp/exercises/nth-prime/Example.fs