Skip to content

Commit

Permalink
if only we have used purely functional data structures...
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgian committed Oct 20, 2012
1 parent e82ebc2 commit 43daa0a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions problem47.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let sieve bound =
let bitmap = Array.make (bound+1) 0 in
let root = bound / 2 in
for i = 2 to root do
if (bitmap.(i) == 0) then
let j = ref (i*2)
in
while (!j <= bound) do
bitmap.(!j) <- bitmap.(!j) + 1;
j := !j + i;
done;
done;
bitmap
;;


let solve =
let primes = sieve 1000000 in
let rec consecutive n acc =
match (primes.(n)) with
| 4 -> if ((acc+1)=4) then (n-3) else consecutive (n+1) (acc+1)
| _ -> consecutive (n+1) 0
in
consecutive 2 0
;;

1 comment on commit 43daa0a

@nickgian
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had*

Please sign in to comment.