Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. let rec ins z = function
  2. | [] -> [[z]]
  3. | x::xs ->
  4. let res = ins z xs
  5. let res1 = List.map (fun t -> x::t) res
  6. (z::x::xs)::res1
  7.  
  8. let rec ins z = function
  9. | [] -> [[z]]
  10. | x::xs as L ->
  11. (z::L)::(List.map (fun t -> x::t) (ins z xs))
  12.  
  13. ins 0 [1;2;3]
  14.  
  15. let rec perm = function
  16. | [] -> [[]]
  17. | x::xs ->
  18. let res = perm xs
  19. res |> List.map (fun t -> ins x t) |> List.concat
  20.  
  21. let rec perm = function
  22. | [] -> [[]]
  23. | x::xs ->
  24. perm xs |> List.collect (fun t -> ins x t)
  25.  
  26. perm [1;2;3]
  27.  
  28. let fact n = List.length(perm [1..n])
  29.  
  30. fact 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement