How can I write a function which has two parameters and it should generate combination of arbitrary range bits, for example: function[n, k], with n being range, k being number of 1 digits. If I define n = 4 and k = 2, the function should return the following set (in any order):
function[4, 2]
{"1100", "1010", "1001", "0110", "0011", "0101"}
Permutations[PadLeft[ConstantArray[1, k], n]]– Kuba Sep 13 '13 at 20:25Permutations@UnitStep@Range[k-n, k-1]– ybeltukov Sep 13 '13 at 20:31InnerorOuterorKroneckerProductorMaporApply... also, if this is just a slight variation of this question, you might edit it (I rather wouldn't do so, as you have 3 answers here already to the existing question) or formulate a new question. The community can certainly help you better than I can do all alone. – Pinguin Dirk Sep 14 '13 at 07:44