Skip to content

Commit 3610301

Browse files
committed
regular update
1 parent ef27779 commit 3610301

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

ProjectEuler/gen_prime.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let get_seq n =
2+
let rec aux acc n =
3+
if n = 0 then acc
4+
else aux (n :: acc) (n - 1)
5+
in
6+
aux [] n
7+
8+
9+
let gen_prime n =
10+
let update x step lst =
11+
let rec aux acc cur y =
12+
match y with
13+
| [] -> List.rev acc
14+
| h :: hs -> begin
15+
if cur < h then aux acc (cur + step) y
16+
else if h < cur then aux (h :: acc) cur hs else aux acc (cur + step) hs
17+
end
18+
in
19+
aux [] x lst
20+
in
21+
22+
let rec aux acc lst =
23+
match lst with
24+
| [] -> List.rev acc
25+
| x :: xs -> begin
26+
if x * x > n then aux (x :: acc) xs
27+
else aux (x :: acc) (update (x*x) x xs)
28+
end
29+
in
30+
aux [] (List.tl (get_seq n))
31+
32+
let y = gen_prime 10000000

ProjectEuler/p007.ml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
let get_seq n =
2+
let rec aux acc n =
3+
if n = 0 then acc
4+
else aux (n :: acc) (n - 1)
5+
in
6+
aux [] n
7+
8+
9+
let gen_prime n =
10+
let update x step lst =
11+
let rec aux acc cur y =
12+
match y with
13+
| [] -> List.rev acc
14+
| h :: hs -> begin
15+
if cur < h then aux acc (cur + step) y
16+
else if h < cur then aux (h :: acc) cur hs else aux acc (cur + step) hs
17+
end
18+
in
19+
aux [] x lst
20+
in
21+
22+
let rec aux acc lst =
23+
match lst with
24+
| [] -> List.rev acc
25+
| x :: xs -> begin
26+
if x * x > n then aux (x :: acc) xs
27+
else aux (x :: acc) (update (x*x) x xs)
28+
end
29+
in
30+
aux [] (List.tl (get_seq n))
31+
32+
(* n must be less than the size of x *)
33+
let rec get_nth n x =
34+
if n > List.length x then raise (Failure "n must not be larger than the length")
35+
else if n = 1 then List.hd x else get_nth (n - 1) (List.tl x)
36+
37+
38+
let p_list = gen_prime 1000000
39+
(* let ans = get_nth 10001 (gen_prime 1000000); *)
40+
41+

ProjectEuler/p099.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import urllib, math
2+
3+
fin = urllib.urlopen ('http://projecteuler.net/project/base_exp.txt');
4+
5+
mx = -1;
6+
cnt = 0;
7+
while True:
8+
s = fin.readline();
9+
if len (s) == 0:
10+
break
11+
[a, b] = map (int, s.split(','));
12+
t = b * math.log (a);
13+
cnt += 1;
14+
if t > mx:
15+
mx = t;
16+
ans = cnt;
17+
print ans;
18+
19+

0 commit comments

Comments
 (0)