-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem46.ml
More file actions
29 lines (27 loc) · 806 Bytes
/
problem46.ml
File metadata and controls
29 lines (27 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
open Euler
let perfectSquare n =
let fp = sqrt n in
fp = (floor fp)
;;
let solve =
let primes = Primes.sieve 10000 in
primes.(1) <- true;
let checkGoldbach n =
let rec iterPrimes i =
match primes.(i) with
| true -> (
match i with
| pr when (pr>n) -> false
| pr -> if perfectSquare ((float (n - pr))/.2.) then true
else iterPrimes (i+1))
| false -> iterPrimes (i+1)
in
iterPrimes 1
in
let rec iterArray i =
match primes.(i), (isOdd i) with
| false, true -> if (checkGoldbach i) then iterArray (i+1) else i
| _,_ -> iterArray (i+1)
in
iterArray 33
;;