Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source).
A valid answer:
- Takes a number \$w\$ and (assumed non-negative) integer \$x\$.
- Starts with an integer list with a length of \$2^w\$, initially filled with zeroes.
- For each number \$n\$ from \$0\$ to \$w-1\$ (inclusive), divides the list into sub-lists of size \$2^n\$, then increments all of the values in the sub-list that contains the index \$x\$.
- Returns this list
(Of course a program doesn't have to do exactly this if it returns the right results. If someone finds a good declarative algorithm I will upvote it.)
Examples
(examples are 0 indexed, your answer doesn't have to be)
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
Example of basic algorithm for \$w=3, x=5\$
- List is \$[0,0,0,0,0,0,0,0]\$
- \$n\$ is \$0\$, list is split into \$[[0],[0],[0],[0],[0],[0],[0],[0]]\$, \$x\$ is in sixth sub-list, list becomes \$[0,0,0,0,0,1,0,0]\$
- \$n\$ is \$1\$, list is split into \$[[0,0],[0,0],[0,1],[0,0]]\$, \$x\$ is in third sub-list, list becomes \$[0,0,0,0,1,2,0,0]\$
- \$n\$ is \$2\$, array is split into \$[[0,0,0,0],[1,2,0,0]]\$, \$x\$ is in second half, array becomes \$[0,0,0,0,2,3,1,1]\$
- Result is \$[0,0,0,0,2,3,1,1]\$
00000000
->00001111
->00002211
->00002311
. \$\endgroup\$