Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Power-set/OCaml/power-set-1.ocaml
Normal file
17
Task/Power-set/OCaml/power-set-1.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module PowerSet(S: Set.S) =
|
||||
struct
|
||||
|
||||
include Set.Make (S)
|
||||
|
||||
let map f s =
|
||||
let work x r = add (f x) r in
|
||||
fold work s empty
|
||||
;;
|
||||
|
||||
let powerset s =
|
||||
let base = singleton (S.empty) in
|
||||
let work x r = union r (map (S.add x) r) in
|
||||
S.fold work s base
|
||||
;;
|
||||
|
||||
end;; (* PowerSet *)
|
||||
1
Task/Power-set/OCaml/power-set-2.ocaml
Normal file
1
Task/Power-set/OCaml/power-set-2.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let subsets xs = List.fold_right (fun x rest -> rest @ List.map (fun ys -> x::ys) rest) xs [[]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue