fork download
  1. let product xs0 n0 =
  2. let g xss = List.flatten (List.map (fun xs -> List.map (fun x -> xs @ [x]) xs0) xss) in
  3. let rec h xss n = if n == 1 then xss else h (g xss) (n - 1) in
  4. h (List.map (fun x -> [x]) xs0) n0
  5. ;;
  6. module IntMap = Map.Make(struct type t = int let compare = compare end)
  7. let histogram is =
  8. let count map i = if IntMap.mem i map then IntMap.find i map else 0 in
  9. List.fold_left (fun map i -> IntMap.add i (succ (count map i)) map) IntMap.empty is
  10. ;;
  11. let sum = List.fold_left (+) 0;;
  12. let sum_v map = IntMap.fold (fun k v a -> a + v) map 0;;
  13. let f9134 xs n =
  14. let map = histogram (List.map sum (product xs n)) in
  15. let total = float_of_int (sum_v map) in
  16. print_string "出目\t出現回数\t出現率\n";
  17. IntMap.iter (fun k v -> Printf.printf "%d\t%d\t%f\n" k v (100.0 *. float_of_int v /. total)) map
  18. ;;
  19. let () = f9134 [1; 2; 3; 4; 5; 6] 3;;
  20.  
Success #stdin #stdout 0s 16816KB
stdin
Standard input is empty
stdout
出目	出現回数	出現率
3	1	0.462963
4	3	1.388889
5	6	2.777778
6	10	4.629630
7	15	6.944444
8	21	9.722222
9	25	11.574074
10	27	12.500000
11	27	12.500000
12	25	11.574074
13	21	9.722222
14	15	6.944444
15	10	4.629630
16	6	2.777778
17	3	1.388889
18	1	0.462963