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.119 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.118 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.117 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.116 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.115 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.114 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.113 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.111 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.110 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.109 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.108 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.107 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.106 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.105 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.104 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.103 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.102 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.101 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.100 tracks/fsharp/exercises/nth-prime/Example.fs
trackler-2.2.1.99 tracks/fsharp/exercises/nth-prime/Example.fs