Reveal by Halves (in need of a better name)
array-manipulation code-golf subsequence matrix
Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source).
A valid answer:
- Takes a number \$w\$ and (assumed non-negative) integer \$x\$.
- Outputs an integer list with a length of \$2^w\$, initially filled with zeroes.
- For each number \$n\$ from \$0\$ to \$w-1\$ (inclusive), divide the list into sub-lists of size \$2^n\$, then increment all of the values in the sub-list that contains the index \$x\$.
Examples
(with coordinates from left, 0 indexed, but your answer may have change these)
w=3, x=1
23110000
w=2, x=2
0021
w=3, x=5
00002311
w=4, x=4
1111432200000000
w=2, x=100
Do not need to handle (can do anything) because x is out of bounds
Meta questions
- Are these tags fitting?
- Would this be better in one dimension? (like \$3, 2\$ returns
11320000
) Edit: I've changed it to one dimension but I can revert if it makes it less interesting. - Should \$w\$ or \$2^w\$ be the input?
- Is this a duplicate?