Generate all combinations of given list of elements, sorted
Jelly, 1 byte
ṗ
TryItOnline
Cartesian power built-in atom, as a dyadic link with left argument the items and right argument the count, or as a full program with first argument the items and second argument the count.
Haskell, 20 bytes
(mapM id.).replicate
Usage exaple:
*Main> ( (mapM id.).replicate ) 2 "01"
["00","01","10","11"]
*Main> ( (mapM id.).replicate ) 2 "10"
["11","10","01","00"]
replicate
makes n
copies of the 2nd parameter and mapM id
builds the combinations. Btw, mapM id
is the same as sequence
, but 1 byte less.
MATL, 2 bytes
Z^
Cartesian power builtin...
Try it online!