User Tools

Site Tools


ex-l6-sol

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ex-l6-sol [2014/10/29 11:56]
giovanni.casu created
ex-l6-sol [2015/10/08 15:20] (current)
Line 35: Line 35:
   n when n<=0 -> None   n when n<=0 -> None
 | n -> Some (fibR n);;</​code>​ | n -> Some (fibR n);;</​code>​
 +  - .
 +    - .<code ocaml>​let is_complete (Mazzo l) =
 + (List.length l) = 40 &&
 + not (dup l) &&
 + List.fold_right (fun x y -> (is_card_correct x) && y) l true;;</​code>​
 +    - .<code ocaml>​let seme_of_int = function
 + 1 -> Picche
 +  | 2 -> Cuori
 +  | 3 -> Denari
 +  | 4 -> Fiori
 +  | _ -> failwith "​seme_of_int:​ numero non gestito";;​
 +let suitify n = List.map (fun x -> Carta(n, seme_of_int x)) (range 1 4);;
 +let new_mazzo = fun () ->
 +  Mazzo (List.flatten (List.map suitify (range 1 10)));;</​code>​
 +    - .<code ocaml>​let partition (Mazzo l) =
 + let seme_filter s = List.filter (fun (Carta(n,​x)) -> x=s) in
 + (Mazzo(seme_filter Picche l),
 + ​ Mazzo(seme_filter Cuori l),
 + ​ Mazzo(seme_filter Denari l),
 + ​ Mazzo(seme_filter Fiori l));;</​code>​
 + 
ex-l6-sol.txt · Last modified: 2015/10/08 15:20 (external edit)