I’ve just made these bash functions to play with combinatorics from the commandline:
Example usages:
$ setintersection "1 2 3" "2 3"
['3', '2']
$ setproduct "1 2 3" "a b"
[('1', 'a'), ('1', 'b'), ('3', 'a'), ('3', 'b'), ('2', 'a'), ('2', 'b')]
$ permutations "1 2 3"
[('1', '2', '3'),
('1', '3', '2'),
('2', '1', '3'),
('2', '3', '1'),
('3', '1', '2'),
('3', '2', '1')]
$ powerset "1 2 3"
[(),
('1',),
('2',),
('3',),
('1', '2'),
('1', '3'),
('2', '3'),
('1', '2', '3')]
$ permutationspartial "1 2 3" 2
[('1', '2'), ('1', '3'), ('2', '1'), ('2', '3'), ('3', '1'), ('3', '2')]
$ combinations "1 2 3" 2
[('1', '2'), ('1', '3'), ('2', '3')]
Grab these functions and more from my macinit script.