-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
if only we have used purely functional data structures...
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
;; |
43daa0a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had*