WolframLang: List Combinatorics

By Xah Lee. Date: . Last updated: .
Tuples
  • Tuples[ list, n]
  • and more

return all possible n-tuples.

Tuples

Tuples[ {1,2,3}, 2] ===
{{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}}
Subsets
  • Subsets[list] → all subsets.
  • Subsets[list, n] → max subset length n.
  • Subsets[list, {n}] → subset length exactly n.
  • Subsets[list, {n, m}] → subset length n to m.
  • Subsets[list, spec, s] → first s subsets.

return all possible subsets

Subsets

xx = {1,2,3};

Subsets[xx] ===
{{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}

(* max length n in each subset. *)
Subsets[xx, 2] ===
{{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}}

(* exact length n in each subset. *)
Subsets[xx, {2}] ===
{{1, 2}, {1, 3}, {2, 3}}

(* length n to m in each subset. *)
Subsets[xx, {2,3}] ===
{{1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}

(* just first 4 subsets. *)
Subsets[xx, 2, 5] ===
{{}, {1}, {2}, {3}, {1, 2}}
Permutations

Permutations

WolframLang List Operations