[Question]
  [
Inspired by this: <http://nolandc.com/smalljs/mouse_reveal/> [(source)](https://github.com/NolanDC/smalljs/tree/master/mouse_reveal).
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]\$
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
2*Ḷ^‘l2Ċ⁸_
```
A dyadic Link that accepts \$w\$ on the left and \$x\$ on the right and yields a list of integers.
**[Try it online!](https://tio.run/##y0rNyan8/99I6@GObXGPGmbkGB3petS4I/7////G/00B "Jelly – Try It Online")**
### How?
```
2*Ḷ^‘l2Ċ⁸_ - Link: integer, w; integer x   e.g.  3; 5
2          - two                                 2
 *         - (2) exponentiate (w)                8
  Ḷ        - lowered range                       [0,1,2,3,4,5,6,7] 
   ^       - XOR (x)                             [5,4,7,6,1,0,3,2]
    ‘      - increment                           [6,5,8,7,2,1,4,3]
     l2    - log base two                        [2.58,2.32,3,2.80,1,0,2,1.58]
       Ċ   - ceiling                             [3,3,3,3,1,0,2,2]
        ⁸  - chain's left = w                    3
         _ - subtract                            [0,0,0,0,2,3,1,1]
```
---
Without floating points involved, also 10: `2*Ḷ^ḤBẈ⁸_‘`  
...would be 8 if `0` in binary were `[]` rather than `[0]` (`2*Ḷ^BẈ⁸_`)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
ox<Ÿ^bεÀ1k
```
[Try it online!](https://tio.run/##yy9OTMpM/f8/v8Lm6I64pHNbDzcYZv//b8RlBAA "05AB1E – Try It Online") or [Try all cases!](https://tio.run/##yy9OTMpM/V9WmVD8P7/C5uiOuKRzWw83GGb/r9X5Hx1trGMYq6MQbaRjBKKMdUxBlImOSWwsAA)
The idea is to count for each index how many leading bits are the same as \$x\$'s bits.
`ox<Ÿ` push integers between \$2^w\$ and \$2^{w+1}-1\$.  
`^` xor every integer in the range with \$x\$.  
`b` convert each number to binary.  
`ε` for each binary string:  
`À` rotate the leading \$1\$ to the back.  
`1k` find the index of the first \$1\$. This is first bit that differs between the current index and \$x\$.
[Answer]
# [J](http://jsoftware.com/), 29 28 27 bytes
```
+/@(<./\)@({=|:@])2#:@i.@^]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tfUdNGz09GM0HTSqbWusHGI1jZStHDL1HOJi/2typSZn5CsYKqQpGEOYRgrGQK4hUD8E6lohy4JEjIACQFEjoKgRQhQiA9ELlDVF6DGEQhOgrBEQGqBBoGoToGqT/wA "J – Try It Online")
Consider `1 f 3`:
* `[:#:@i.2^]` Numbers 0 through `2^n-1` in binary:
```
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
```
* `{` From those, the item at index 1:
```
0 0 1
```
* `=|:@]` Check elementwise equality between that and every number from step 1
(note only the element itself is equal everywhere `1 1 1`). We also transpose
the result:
```
1 1 1 1 0 0 0 0
1 1 0 0 1 1 0 0
0 1 0 1 0 1 0 1
```
* `<./\` Column-wise cumulative minimum:
```
1 1 1 1 0 0 0 0
1 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0
```
* `+/` Column-wise sum:
```
2 3 1 1 0 0 0 0
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 22 bytes
```
W:~Ti(1Gq:W"t@etaY|1e+
```
Inputs *w*, then *x*, where *x* is 1-based.
[Try it online!](https://tio.run/##y00syfn/P9yqLiRTw9C90CpcqcQhtSQxssYwVfv/fxMuUwA) Or [verify all test cases](https://tio.run/##y00syfmf8D/cqi4kU8PQvdAqXKnEIbUkMbLGMFX7f6xLVEXIf2MuIyA0BkIzLhMuUwA).
### Explanation
```
W       % Input (implicit): w. Exponential with base 2. Gives 2^w
:~      % Range, negate. Gives [0 0 ... 0] (row vector with length 2^w)
T       % Push true (1)
i       % Input: x
(       % Write 1 at position x (1-based). Gives for example [0 1 0 0 0 0 0 0]
1G      % Push w again
q:      % Subtract 1, range. Gives [1 2 ... w-1]
W       % Exponential with base 2, element-wise. Gives [2 4 ...2^(w-1)]
"       % For each k in [2 4 ...2^(w-1)]
  t     %   Duplicate the current row vector; initially [0 1 0 0 0 0 0 0]
  @e    %   Reshape with k rows, in column-major order. For example, for k=2 this
        %   gives [0 0 0 0;
        %          1 0 0 0] 
  ta    %   Duplicate, any. For each column, gives true if there is some nonzero
        %   In the example this gives [1 0 0 0] 
  Y|    %   Logical "or", element-wise with broadcast. In the example this gives
        %   [1 0 0 0;
        %    1 0 0 0]
  1e    %   Reshape with 1 row. In the example this gives [1 1 0 0 0 0 0 0]
  +     %   Add, element-wise. In the example this gives [1 2 0 0 0 0 0 0]
        % End (implicit)
        % Display (implicit)
```
[Answer]
# [Haskell](https://www.haskell.org/), 59 bytes
```
0#x=[0]
w#x|(a,b:c)<-splitAt x$(w-1)#div x 2<*".."=a++b+1:c
```
[Try it online!](https://tio.run/##LU7LbsIwELz7K1YECad51I/0QmMk7vwB4mCwaa2GxHLcxkj8e9i0ndPOjGZnPvX4ZbtunlmW1JGdyJSlB9XleXvJ22r0nYv7CGlNp4rnmXE/kEC0L6u6XildFOeCby/zTbtemYEAdeWAsetNe2rC4EHm9eh1T1/Vptrk7Xr3YePB9ZZAZ@NxKtNJBasNGtMQzAju/f4r1P47WFTxpw@ujxRnKXUvMYENBJbGWQKHagdCcs4QRIBYOGOCEwlvfzcy9EkDzcI5opFCsH88AQ "Haskell – Try It Online")
## How?
Recursive implementation, starting from the base case `0#x=[0]`. To compute `w#x`, perform the following steps (exemplified with `w=3`, `x=1`).
```
Compute (w-1)#div x 2                   -- 2#0 = [2,1,0,0]
Duplicate every number                  -- [2,2,1,1,0,0,0,0]
Add +1 to the number at position x      -- [2,3,1,1,0,0,0,0]
```
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), ~~22~~ 18 bytes
-4 bytes thank sto coltim!
```
{+/&\t=(+t:!x#2)y}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/NqlpbXy2mxFZDu8RKsULZSLOy9n9atLG1YSxXWrSRtRGIMrY2BVEm1iax/wE "K (ngn/k) – Try It Online")
[Answer]
# JavaScript (ES6), 60 bytes
Expects `(w)(x)`. Returns a string.
```
w=>g=(x,i)=>i>>w?'':(h=k=>k--&&!((i^x)>>k)+h(k))(w)+g(x,-~i)
```
[Try it online!](https://tio.run/##ZYzNDoIwEITvPAVeYDdYaQteTLq@iQlBfmoJNWKEk69eN0QP6pe5zTdzqR7VVN/s9S5Gf25Ca8JsqDOwbC0askTzMU0P0BtnyAmRJBsAe1qQyGHWg0OEGbOOffG0GGo/Tn5odoPvoIUCQSHGeR7rQinJRN@CRs4qSKlV9Lfef0qu@eFHKJGzCoopC63lm/AC "JavaScript (Node.js) – Try It Online")
[Answer]
# Java, ~~88~~ ~~85~~ 84 bytes
```
x->w->{int a,r[]=new int[w=1<<w];for(;w>1;)for(a=w/=2;a-->0;++r[a+x/w*w]);return r;}
```
*Saved 1 byte thanks to [Olivier Grégoire](https://codegolf.stackexchange.com/users/16236).*
[Try it online!](https://tio.run/##pZC9boMwFIV3nsIjLsEpaTMZLHWp1KFTRsTgEkCmYCP7EgdFPDt1xM@SLb2Lv3uOdXTsml94WJ9/J9F2SgOq3U56EA350JoPhnoPRtnLHISS5HMB6nld/9OIHOUNNwZ9cyHRzUNuFt0AB3dclDij1rn@CbSQVZohriuD57v3WSPjLwlFVejdgyAkpBljZTJdQ2ZDdnMC4judZoksLLrbNoni2Ga0VNqnlkUU34kndp8cKA9D9kqDQKc8uO7ti80w1QX0WiJNx2ktQrdKp8FA0RLVA@lcaWikP38NATU/wy8J77pm8CO8wBvG@KmEA97gyYTjvzu84w3WhNEbpz8)
[Answer]
# [R](https://www.r-project.org/), ~~50~~ 46 bytes
```
function(w,n)w+-log2(bitwXor(1:2^w-1,n)+1)%/%1
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jXCdPs1xbNyc/3UgjKbOkPCK/SMPQyiiuXNcQKKNtqKmqr2r4P03DRMdEkytNw1jHVPM/AA "R – Try It Online")
A function taking `w` and `n` as arguments and returning a vector of integers. Saved 18 bytes by changing tack to an R version of [@JonathanAllan’s clever Jelly solution](https://codegolf.stackexchange.com/a/225467/42248).
Thanks to @pajonk for saving 4 bytes!
---
# Original version: [R](https://www.r-project.org/), 68 bytes
```
function(w,n)colSums(matrix(1:2^w-1,w,2^w,T)%/%(y=2^(1:w-1))==n%/%y)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jXCdPMzk/J7g0t1gjN7GkKLNCw9DKKK5c11CnXAdI64RoquqralTaGsUBJYDCmpq2tnlAoUrN/2kaJjommv8B "R – Try It Online")
[Answer]
# Haskell, 59 bytes
```
w%x=[sum[1|k<-[0..w-1],i`div`2^k==x`div`2^k]|i<-[0..2^w-1]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/X0NZ0zYls0xPwyhOk6tctcI2urg0N9qwJttGN9pAT69c1zBWJ1M529a2Qjk7tiYTImoUBxKP/Z@bmJlnW1CUmVeiYaxqqPkfAA "Haskell – Try It Online")
For each `i` in `[0..2^w-1]` we count all the `k ∈ [0..w-1]` such that \$ \big\lfloor \frac{\mathtt i}{2^\mathtt k} \big\rfloor = \big\lfloor \frac{\mathtt x}{2^\mathtt k} \big\rfloor \$.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~57~~ 54 bytes
The same approach as [my other answer](https://codegolf.stackexchange.com/a/225456/64121).
-3 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!
```
lambda w,x:[w+3-len(bin(2*(n^x)))for n in range(2**w)]
```
[Try it online!](https://tio.run/##FYpBCsIwEADvvmKPu3U9mNRLwZekKaTYaKBuSygkvj51TwMzs/@Ozya2xefY1vCdXwEK18GVq72ti@CcBE2HMlUiilsGgSSQg7yXv@8K@aa2MFQNzlm@ewZn2CgsPxQ9994PF4A9Jzkwov5E7QQ "Python 3 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 26 bytes
```
Ṭo2*0ẋƲ}WŒH€Ẏ$⁹Ð¡ḊSṁ$€€F€S
```
[Try it online!](https://tio.run/##y0rNyan8///hzjX5RloGD3d1H9tUG350ksejpjUPd/WpPGrceXjCoYUPd3QFP9zZqAIUBSI3IA7@//@/6X8TAA "Jelly – Try It Online")
This is probably entirely the wrong approach.
```
Ṭo2*0ẋƲ}WŒH€Ẏ$⁹Ð¡ḊSṁ$€€F€S  Main Link; take `x` on the left and `w` on the right; `x` is one-indexed
Ṭ                           An array with a 1 in index `x`
 o                          Logical OR with (to get the array to the right size)
  ----Ʋ}                    (Four links applied to the right argument)
  2*0ẋ                      [0] * (2 ^ w)
        W                   Wrap this into a list; [[0, ..., 1, ..., 0]]
              ⁹Ð¡           Repeat w times, collecting intermediate results
         [.]-$              (Apply these two links)
         ŒH€                Split each sublist into two halves
            Ẏ               Tighten; dump these halves into the list itself
                 Ḋ          Remove the first sublist (we could also decrement the final sum)
                      €     For each stage / collected intermediate
                  --$€      For each sublist, apply two links
                  S         Sum of the list (could be maximum too)
                   ṁ        Molded to the shape of the list
                       F€   Flatten each
                         S  and sum the result
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
2*rḤ$Ṗ^Bṙ€1i€1’
```
[Try it online!](https://tio.run/##y0rNyan8/99Iq@jhjiUqD3dOi3N6uHPmo6Y1hpkg4lHDzP///5v8NwEA "Jelly – Try It Online")
Port of [ovs' 05AB1E answer](https://codegolf.stackexchange.com/a/225456/66833)
## How it works
```
2*rḤ$Ṗ^Bṙ€1i€1’ - Main link. Takes W on the left and X on the right
2*              - 2 ** W
    $           - Last 2 links as a monad f(2 ** W):
   Ḥ            -   2 ** (W+1)
  r             -   Inclusive range
     Ṗ          - Right-exclusive range
      ^         - XOR with X
       B        - Convert to binary
        ṙ€1     - Rotate each one step to the left
           i€1  - First index of 1 in each
              ’ - Decrement
```
[Answer]
# C++, 86 bytes
```
[](int w,int x){int*r=new int[w=1<<w],a;for(;a=w/=2;)for(;a--;++r[a+x/w*w]);return r;}
```
[Try it online!](https://tio.run/##VZBNbsMgEIX3PsVIXRhirMRusgmQi1AWCOMKKcERxsVSlbM7EFv9mc2b92YYfULf7/Wn1subdfo6dYbZYQzeqNul@BpsB8GMAakpDNAT6wJEAllm/F1AqtTvwAOHHkUyY/oK@8GjvGRTfqBJGDTAGMTUVxWGMXTnsx6mkEMvrMxaQrm@/jctP9wWd@ZqghHS0@JR5Os3ZR1KGCscX4REK@DGl9E8dyZmSBF5w1iURNFMRxWPe95SvJq6plXlharmfdxFiak3YfIOPH0stHh9QU/eSYN/TEta/Gdy@jVHckxmO3BIsMsT)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
Ż2*ṪḶ:ⱮƊ=":@ɗS
```
[Try it online!](https://tio.run/##y0rNyan8///obiOthztXPdyxzerRxnXHumyVrBxOTg/@b/2oYY6Crp3Co4a51oeX63Mdbn/UtCby//9ormhjHcNYHa5oIx0jEGWsYwqiTHRMYrliAQ "Jelly – Try It Online")
A dyadic link taking `w` as the left argument and `x` as the right. Returns a list of integers
## Explanation
```
Ż              | 0..w
 2*            | 2 to the power of each of these
            ɗ  | Following as a dyad:
       Ɗ       | - Following as a monad
   Ṫ           |   - Tail
    Ḷ          |   - Range from 0 to this
     :Ɱ        |   - Integer divide by the remaining powers of two
        ="     | - Equal to:
          :@   |   - n integer divided by the same powers of two
             S | Sun
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 22 bytes
```
ＮθＮη⭆Ｘ²θΣＥθ⁼÷ηＸ²λ÷ιＸ²λ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05oLmZ8B5AcUZeaVaASXAKl038QCjYD8cqCMkY5CoaaOQnBprgZIsFBHwbWwNDGnWMMzr8QlsywzJVUjQ0cBrjZHE6gYIZWJKgUG1v//GyuY/tctywEA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ                      First input as a number
  Ｎη                    Second input as a number
      ²                 Literal `2`
     Ｘ                  Raised to power
       θ                First input
    ⭆                   Map over implicit range and join
          θ             First input
         Ｅ              Map over implicit range
                  ι     Outer index
                 ÷      Integer divided by
                    ²   Literal 2
                   Ｘ    Raised to power
                     λ  Inner index
           ⁼            Equals
             η          Second input
            ÷           Integer divided by
               ²        Literal 2
              Ｘ         Raised to power
                λ       Inner index
        Σ               Take the sum
                        Implicitly print
```
Outputs a string, so only works for `w<10`. Add 1 byte to output a list.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 13 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Ç┌┼σc┤0Θ▬-◙♂A
```
[Run and debug it](https://staxlang.xyz/#p=80dac5e563b430e9162d0a0b41&i=1,3%0A2,2%0A5,3%0A4,4&m=2)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 54 bytes
```
w=>g=(x,i)=>i>>w?'':(l=v=>v?l(v>>1)-1:w)(i^x)+g(x,-~i)
```
[Try it online!](https://tio.run/##ZYzBDoIwEETvfAU3dqNIt@CFpMufmBAEUtNQIqZw8tfrhuhBfZnbvJlbG9qlu9v5kU/@2sfBxNXwaGA7WjRsmdcmy2pwJhgOjYPATJhTvSLYy4aHUcz8aTF2flq860/OjzBAiUCIaVGkuiRSQvItaJTsglKakr/1@VNKLQ8/QoWSXSChKrVWb@IL "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 55 bytes
```
x=>g=(w,n=0,h=_=>g(w,n+!(x>>w)))=>w--?h()+h():(x--,[n])
```
[Try it online!](https://tio.run/##XYzNCsIwEITvPkW97dLE5qdehMQHEZFS@6OURKyYvH3cFBHsMHsY9pu5N@9mbp@3x4s7f@1Sb1I0djAQmDOCjeZCKYdyC9HagIjGBs6PI2BJd4DIOTu5M6bWu9lP3W7yA/QgETRiUVWF0lIK0uYfUEheACGUXD33v3Zu5oUVUCN5ASSp1kqJr9IH "JavaScript (Node.js) – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), 48 bytes
```
w$x=[w+1-ndigits(2(n⊻x),base=2) for n=0:2^w-1]
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v1ylwja6XNtQNy8lMz2zpFjDSCPvUdfuCk2dpMTiVFsjTYW0/CKFPFsDK6O4cl3D2P8grka5jkKFpkJmnkJ0tLGOYayOQrSRjhGIMtYxBVEmOiaxsVwKCgVFmXklOXkaQFs0uVLzUv4DAA "Julia 1.0 – Try It Online")
Port of [ovs's answer](https://codegolf.stackexchange.com/a/225461/98541)
]