Disclaimer
This question is not a duplicate of this question. I'm not counting specific digits, as we already have those set in the initial parameters. This question is focusing on the decimal numbers that can be constructed from the binary strings based on the digits provided.
Challenge
Given two integers X
and Y
, representing the number of zeroes (0
) and ones (1
) respectively, calculate all the possible decimal equivalents that can be determined from creating binary strings using only the zeroes and ones provided, and display them as output.
Example 1:
Input: 0 1
Output: 1
Explanation: Only one 1
to account for, which can only be converted one way.
Example 2:
Input: 1 1
Output: 1,2
Explanation: 01
converts to 1, 10
converts to 2.
Example 3:
Input: 3 2
Output: 3,5,6,9,10,12,17,18,20,24
Explanation: Three 0
s and two 1
s make 00011
(3), 00101
(5), 00110
(6), 01001
(9), 01010
(10), 01100
(12), 10001
(17), 10010
(18), 10100
(20), 11000
(24)
Limitations and Rules
- I will only expect your code to work where
0 < X + Y <= 16
so the maximum number in the output could only occur from 161
s, i.e. parameters0
and16
. - As a result of the above limitation, the range of numbers we'd expect in the output are from
0
and65535
. - I will accept functions or code, so long as the resulting output is provided, whether this be a comma separated list, an array, list outputted to STDOUT, etc. The only criteria I must stress about the output is that it must be sorted.
- This is code golf, minimum bytes will receive maximum glory.
- We will not tolerate silly loopholes
0 0
? \$\endgroup\$0 <= X + Y <= 16
, so yes, because0 0
would be considered valid input that satisfies that rule. \$\endgroup\$0 0
? The number 0 can be represented by zero, one or more zeroes. \$\endgroup\$