initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
module _58
|
||||
|
||||
open common
|
||||
|
||||
let primeDiagonals =
|
||||
|
||||
let isPrime n =
|
||||
let limit = System.Math.Ceiling(sqrt (float n)) |> int
|
||||
let rec check i =
|
||||
i > n/limit || (n % i <> 0 && check (i + 1))
|
||||
check 2
|
||||
|
||||
// let isPrime = isPrimeW [2I;3I]
|
||||
|
||||
let sideLengthPrimeCount l = 1 + (l - 1) * 2
|
||||
|
||||
let sideLengths =
|
||||
(2,2) |> Seq.unfold(
|
||||
fun (l, r) ->
|
||||
match r with
|
||||
| 0 -> Some(l, (l + 2, 3))
|
||||
| _ -> Some(l, (l, r - 1))
|
||||
)
|
||||
sideLengths
|
||||
|> Seq.scan (fun (c,_) l -> (c + (l), l + 1)) (3,3)
|
||||
|> Seq.scan (fun (p,_) (d,l) ->
|
||||
let r = isPrime (d)
|
||||
match r with
|
||||
| true -> (p + 1, l)
|
||||
| false -> (p, l)
|
||||
) (0,0) |> Seq.skip 1
|
||||
|> Seq.skipWhile (fun (p,l) -> (float p)/(float (sideLengthPrimeCount l)) >= 0.1)
|
||||
|> Seq.nth 1
|
||||
Reference in New Issue
Block a user