Skip to content

Commit

Permalink
added some solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Sep 11, 2018
1 parent afc9e6b commit 55acf49
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions hw1-1.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let rec sigma(a,b,f) =
if a>b-1 then 0
else f(b) + sigma(a,b-1,f)

(*let _ = print_int(sigma(3,2,fun x->x+2))*)
37 changes: 37 additions & 0 deletions hw1-2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let sumprod(f,n,k) =
let x = ref 0.0 in
let y = ref 1.0 in
for i=1 to n do
for j=1 to k do
y := !y *. f(i,j)
done;
x := !x +. !y;
y := 1.0
done;
!x

(*Hello World*)
(*
let rec mult(b,f) =
if b<=0 then 1.0
else f(b) *. mult(b-1,f)
let rec sigma(a,f) =
if a<=0 then 0.0
else f(a) +. sigma(a-1,f)
*)

(*let rec sumprod(M,n,k) =
let x = ref 0.0 in
let y = ref 0.0 in
let kk = ref k in
match (n,k) with
| (0,0) -> !x
| (0,k') -> !x
| (n',0) -> x := !x + !y; y := 0.0; sumprod(M,n'-1,!kk)
| (n',k') -> y := !y * M(n',k') ;sumprod(M,n',k'-1)
let em(a,b) = (float_of_int a)/.(float_of_int b)
*)

10 changes: 10 additions & 0 deletions hw1-3.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type team = Korea | France | Usa | Brazil | Japan | Nigeria | Cameroon
| Poland | Portugal | Italy | Germany | Norway | Sweden | England
| Argentina

type tourna = LEAF of team
| NODE of tourna * tourna

let rec parenize tr =
match tr with
| NODE tr' ->
2 changes: 1 addition & 1 deletion hw14.ml → hw1-5.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
t = ZERO | SUCC of nat
type nat = ZERO | SUCC of nat

let rec natadd (a,b) =
match(a,b) with
Expand Down
3 changes: 0 additions & 3 deletions hw12.ml

This file was deleted.

0 comments on commit 55acf49

Please sign in to comment.