Commits

Yoshifumi YAMAGUCHI  committed 1d64d39

modified perm in euler.ml

  • Participants
  • Parent commits a223582

Comments (0)

Files changed (2)

 *.lock
 *.run
 *.opt
+*.cmx
+*.cmxa
 .omakedb
 .DS_Store
 

File lib/euler.ml

 
 type 'a bintree = LF | Bt of 'a * 'a bintree * 'a bintree
 
+(*********************************************************** 
+ ***************************************** Basic operation 
+ ***********************************************************)
+
 let pow x n = 
   let rec pow_aux accu = function
     | 0 -> accu
   | 1 -> x
   | 2 -> x*x
   | _ -> pow_aux 1 n
-;;
 
 
 let fact_aux n m =
 let sqrt n = int_of_float (sqrt (float_of_int n))
 
 
+(**
+ * Basic list operations 
+ **)
+
 let rec_map f l = List.rev (List.rev_map f l)
 
 
   | [x] -> x
   | x::xs -> max_aux x xs
   | [] -> failwith("Eular.max")
-;;
 
 
 let min l =
   | [x] -> x
   | x::xs -> min_aux x xs
   | [] -> failwith("Eular.min")
-;;
 
 
 let rec bottom = function
   range_aux [] s l
 
 
+(***********************************************************
+ ******************************** Basic algebric functions 
+ ***********************************************************)
+
 let sift n l = List.filter (fun x -> x mod n <> 0) l
 
 
 
 let perm n l =
   let len = fact_aux (List.length l) n in
+  let remove x = List.filter (fun y -> y <> x) in
   let rec perm m xs ret =
-    if m = 0 then ret else ret
+    if m = 0 then ret 
+    else List.map (fun x -> perm (pred m) (remove x xs) (x::ret)) xs
+  in
+  perm n l []
 ;;