Based on the "binary, but with twos" notation mentioned in this numberphile video, write a function that takes a single number as input and outputs all variations of that number in a "binary" system where twos are allowed.
Rules
- Code must only be a function/method, not a full program
- Input is an integer passed as the sole parameter to the function
- Output is all valid variations of the input number converted to "binary, but with twos" notation
- Output is the return value of the function, but can be in whatever format is convenient as long as it's obvious (eg, 3 ints, 3 strings, comma/space delimited string, array of ints, etc), order is unimportant
- In the unlikely event that a language happens to contain a built-in function to achieve the result, it's disallowed
- Shortest code in bytes is the winner
Explanation of the output
By example, if you're passed the number 9
, you can convert it to binary as 1001
, but if you allowed 2
s in each position, you could also write it as 201
(i.e. 2*4 + 0*2 + 1*1
), or 121
(i.e. 1*4 + 2*2 + 1*1
), as shown in this table:
+----+----+----+----+
| 8s | 4s | 2s | 1s |
+----+----+----+----+
| 1 | 0 | 0 | 1 |
| 0 | 2 | 0 | 1 |
| 0 | 1 | 2 | 1 |
+----+----+----+----+
So, if passed 9
, your function would need to return the three numbers, 1001
, 201
and 121
.
Format and order are irrelevant, so long as it's obvious (i.e. [121,201,1001]
, "0201 0121 1001"
, ("1001","121","201")
are valid results when given an input of 9
).
Examples
2
=>10, 2
9
=>1001, 201, 121
10
=>1010, 210, 202, 1002, 122
23
=>2111, 10111
37
=>100101, 20101, 100021, 20021, 12101, 12021, 11221