Skip to content

Commit 55acf49

Browse files
author
Alice
committed
added some solutions
1 parent afc9e6b commit 55acf49

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

hw1-1.ml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let rec sigma(a,b,f) =
2+
if a>b-1 then 0
3+
else f(b) + sigma(a,b-1,f)
4+
5+
(*let _ = print_int(sigma(3,2,fun x->x+2))*)

hw1-2.ml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
let sumprod(f,n,k) =
2+
let x = ref 0.0 in
3+
let y = ref 1.0 in
4+
for i=1 to n do
5+
for j=1 to k do
6+
y := !y *. f(i,j)
7+
done;
8+
x := !x +. !y;
9+
y := 1.0
10+
done;
11+
!x
12+
13+
(*Hello World*)
14+
(*
15+
let rec mult(b,f) =
16+
if b<=0 then 1.0
17+
else f(b) *. mult(b-1,f)
18+
19+
20+
let rec sigma(a,f) =
21+
if a<=0 then 0.0
22+
else f(a) +. sigma(a-1,f)
23+
*)
24+
25+
(*let rec sumprod(M,n,k) =
26+
let x = ref 0.0 in
27+
let y = ref 0.0 in
28+
let kk = ref k in
29+
match (n,k) with
30+
| (0,0) -> !x
31+
| (0,k') -> !x
32+
| (n',0) -> x := !x + !y; y := 0.0; sumprod(M,n'-1,!kk)
33+
| (n',k') -> y := !y * M(n',k') ;sumprod(M,n',k'-1)
34+
35+
let em(a,b) = (float_of_int a)/.(float_of_int b)
36+
*)
37+

hw1-3.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type team = Korea | France | Usa | Brazil | Japan | Nigeria | Cameroon
2+
| Poland | Portugal | Italy | Germany | Norway | Sweden | England
3+
| Argentina
4+
5+
type tourna = LEAF of team
6+
| NODE of tourna * tourna
7+
8+
let rec parenize tr =
9+
match tr with
10+
| NODE tr' ->

hw14.ml renamed to hw1-5.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
t = ZERO | SUCC of nat
1+
type nat = ZERO | SUCC of nat
22

33
let rec natadd (a,b) =
44
match(a,b) with

hw12.ml

-3
This file was deleted.

0 commit comments

Comments
 (0)