[Question]
  [
Given a positive integer \$n\$, your task is to find out the number of partitions \$a\_1+a\_2+\dots+a\_k=n\$ where each \$a\_j\$ has exactly \$j\$ bits set.
For instance, there are \$6\$ such partitions for \$n=14\$:
$$\begin{align}&14 = 1\_2+110\_2+111\_2&(1+6+7)\\
&14 = 10\_2+101\_2+111\_2&(2+5+7)\\
&14 = 10\_2+1100\_2&(2+12)\\
&14 = 100\_2+11\_2+111\_2&(4+3+7)\\
&14 = 100\_2+1010\_2&(4+10)\\
&14 = 1000\_2+110\_2&(8+6)\end{align}$$
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer wins.
### Test cases
```
n  f(n)
-------
1  1
2  1
3  0
4  2
5  1
10 2
14 6
19 7
20 10
25 14
33 32
41 47
44 55
50 84
54 102
59 132
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
ŒṗB§Ṣ⁼JƲ€S
```
[Try it online!](https://tio.run/##y0rNyan8///opIc7pzsdWv5w56JHjXu8jm161LQm@P/D3VsObX24Y9PDHYvCdA63q2i6//9vqKBgyGUEIowVFAy4TBQUjLhMQVxDAyDL0ETBjMvQUsGcy8hAwdCAy8hUwdCEy9hYwdiIy8RQwcScy8REwdSUy9RAwcIEAA "Jelly – Try It Online")
Brute force approach, we generate all partitions then count those that satisfy \$\operatorname{bitsum}(a\_j) = j\$. Times out for the \$n = 59\$ test case on TIO, and can handle a test suite going up to the \$n = 50\$ test cases
## How it works
```
ŒṗB§Ṣ⁼JƲ€S - Main link. Takes n on the left
Œṗ         - Integer partitions of n
  B        - Convert everything to binary
       Ʋ€S - Count for how many the following is true:
   §       -   Sum of bits for each
    Ṣ      -   Sorted
     ⁼J    -   Is equal to [1, 2, ..., n] for some n?
```
[Answer]
# [Python 3](https://docs.python.org/3/), 74 bytes
```
f=lambda n,m=1:sum(f(n-i,m+1)for i in range(n+1)if i.bit_count()==m)+(n<1)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XdBBDoIwEAXQuPUG7pq4aQMYBlpFYy_gJQyo1Sa2EISFZ3HDRu-kp5EwQg3b187_0z5exb265LZpnnWlguS9U_KamuyYEusbCZtbbaiiNtC-8YCpvCSaaEvK1J5P1LakFdGLTFf7Q17bijIpDfOo3QLDxM9kVpS6PVEUCGNkTmDaQzSGGCEcgCNEA4jxCISjG8A7WDpYd7BytTgCriYSKNxtEncSu1wOnXCXw7FJCLcdJicuR_Bf198TcB-II_yh_u-_)
-4 bytes suggested by loopy walt.
---
# [Python 3](https://docs.python.org/3/), 78 bytes
```
f=lambda n,m=1:sum(f(n-i,m+1)for i in range(n+1)if bin(i).count('1')==m)+(n<1)
```
[Try it online!](https://tio.run/##Xc9NDoIwEAXgvaeYxAVtQMPQ1r/Yw4BabWIHgrDw9JW0Sg3bL533Xrv38GhJeG/0s3bNtQYqnMbTa3TMMNrYwuXITduDBUvQ13S/MZrIGmgsMcu3l3akgWWYca0dzxmdkfuutxMahsA5rAFXP6iWICKUM8gI1QxqeYLl4gXKALsExwD7VBtPMNVUKopMS0QQkXIlBpEpR8YmpdK6mHxIOUp@u/6@EPegqPwH "Python 3 – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes
```
ṄƛbṠs:ż⁼;∑
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLhuYTGm2LhuaBzOsW84oG8O+KIkSIsIiIsIjE0Il0=)
```
Ṅ          # Integer partitions
 ƛ      ;  # Map...
  bṠ       # Sums of binary
    s      # Sorted
       ⁼   # Equal to
     :ż    # 1..length?
         ∑ # Sum (count valid)
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 56 bytes
```
f(n,m=1)=!n+sum(i=1,n,if(sumdigits(i,2)-m,0,f(n-i,m+1)))
```
[Try it online!](https://tio.run/##FYpLCsMwDESvomZlkTFE@SyycC9SuggUB0FtTD6Lnt6VF2Jmnl7ZDvV7qZFCjS4jBeHwyP15J6dBkKHR2fjortfpFCP7hAHmekXqhZnrVsr35zL5J5VD82W1a6Mj05hBLwGNoAk0gxaQDHZWZTVufTQ2ta95c1OMLS3XN9c/ "Pari/GP – Try It Online")
A port of [tsh's Python answer](https://codegolf.stackexchange.com/a/240018/9288).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 99 bytes
```
(l=Length)@Select[Flatten[Permutations/@IntegerPartitions@#,1],Tr/@IntegerDigits[#,2]==Range@l@#&]&
```
[Try it online!](https://tio.run/##PcqxCsIwEIDhVykEisJBm1gHh8ANIggOQd1ChlCONJBESM9JfPYoDq7/92fPC2XPcfYt6LZJ@kIl8LLFGyWa2Z6SZ6ZiDdX85O/4KOuA58IUqBpfOf4SCpAO7vVPxxgir1aAclpffQmECUXv@mZqLNwNGAbsXhIU7GCCPcgR5ATyAGp8t/YB "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Åœʒ2вO{āQ}g
```
[Try it online](https://tio.run/##yy9OTMpM/f//cOvRyacmGV3Y5F99pDGwNv3/f0MTAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/w61HJ5@aZHRhk3/1kcbA2vT/Ov@jDXWMdIx1THRMdQwNdAxNdAwtdYwMdIxMdYyBooY6JkAZAx1TIGkZCwA).
**Explanation:**
```
Åœ         # Get all lists of positive integers that sum to the (implicit) input
  ʒ        # Filter this list of lists by:
   2в      #  Convert it to a binary-list
     O     #  Sum each inner list together
      {    #  Sort it
       ā   #  Push a list in the range [1,length] (without popping)
        Q  #  Check if the two lists are the same
  }        # After the filter:
   g       # Pop and push the length to get the amount of remaining lists
           # (which is output implicitly as result)
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 48 bytes
```
Ｎθ≔⁰η⊞υ⁰ＦＬ↨θ²«≔υζ≔⟦⟧υＦΦ⊕θ⁼ι⊖Σ↨κ²Ｆζ⊞υ⁺κλ≧⁺№υθη»Ｉη
```
[Try it online!](https://tio.run/##RY@9jsIwEITry1NsuZZ8EiA6Ko4fCQlQBOXpCl8wsYXjENtLAeLZjU1AdB7PzH67lRKuaoWJcWXPFLbU/EuHHZsUU@91bXHAQSVVkldIHAbpfWwd4FraOij8EV5ix2HEGINb8fVqpeQ1Jd/y948DZf2sLrUJCbKylZONtEEeEpDDoiNhPGoOc/lx9tT0kFMPyZznlCuD91KlIZ99wzJjI849dqdrFTCbHGYt2ZCzmZQPuhel0@lrJnxAlYoxDsfx@2Ie "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ
```
Input `n`.
```
≔⁰η
```
Start with no partitions found.
```
⊞υ⁰
```
Start with `1` partition of `0` integers whose sum is therefore `0`.
```
ＦＬ↨θ²«
```
Loop over the potential lengths of the partitions.
```
≔υζ
```
Save the partitions found so far.
```
≔⟦⟧υ
```
Start collecting partitions of this length.
```
ＦΦ⊕θ⁼ι⊖Σ↨κ²
```
Loop over all integers up to `n` with the right number of bits set.
```
Ｆζ⊞υ⁺κλ
```
Add these integers to all of the previously found partitions.
```
≧⁺№υθη
```
Count how many equal `n`.
```
»Ｉη
```
Output the final total.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 68 bytes
```
f=(n,m,i=1,w)=>n<i?!n:!(w^m)*f(n-i,-~m)+f(n,m,i-~i,-~w)+f(n,m,i+i,w)
```
[Try it online!](https://tio.run/##dY9NDoIwEEb3nAJ2rRRh@iNqRG9iQpCaGihGjOy4OmJaTSywaTLvTWe@ueWvvC0e6v6MdHMph0FmSJOaqAxIh7OjPqhToPcB6s41XkmkI0WivsahNG1R/6m7Xx2q8dtQNLptqnJdNVckEfgY@3Hsg/fP6QJnlicO55ZTh4uFOZDM9wM3fOPyneGpm9POgcQbX8cJ6/jUMWYco1PHwTiezjibT4ipEzbLdmaf4N@cMwuFPQ4YHd4 "JavaScript (Node.js) – Try It Online")
Very slow for `n>25`. Change `!(w^m)*f(...)` to [`(w^m?0:f(...))`](https://tio.run/##dZDNDoIwEITvPgXe2tAK/fOHiLyJCUFraqA1YuTGq1dNq4mrHPvNdmdmz/W97purudyodYej97pElnTElIwMuNzZranmtkDDvqvyQiNLDaFjh3GqwxwdX2D4vFPz/OcbZ3vXHhetOyGNWIJxkmUJm31zPsFF5DngMnIOuJrYw/L/80wGvoR8E/gK5ox7GAzEVRQkbCCCIKC1ZEGQ0EPGTErBctF8DT2UfKf6uUfswQT3Dw) may be faster but cost +1 byte.
[Answer]
# Haskell, ~~77~~ 74 bytes
```
import Data.Bits
m!0=1
m!n=sum[(m+1)!(n-i)|i<-[1..n],popCount i==m]
g=(1!)
```
[Try it Online!](https://tio.run/##FcsxDsMgDEDRPadwNlAbFPZ6abv0DBEDA6JWY4PA2Xp3mi5/efrv2D9p38cgrqUpPKNGdyftE88r@rOC/eDN8MXb2chC9ku3ZfPOSbjWUh/lEAVC5DBlNH62gyMJINRGpxiOFUx2Wl6iKadm4T/7NdjxAw)
-3 bytes thanks to Wheat Wizard
Port of [tsh's Python answer.](https://codegolf.stackexchange.com/a/240018)
[Answer]
# Python3, 156 bytes:
```
def f(n,i=1,c=0):
 if c==n:yield
 elif c<n:
  for k in range(1,n-c+1):
   if bin(k).count('1')==i and c+k<=n:yield from f(n,i+1,c+k)
g=lambda x:len([*f(x)])
```
[Try it online!](https://tio.run/##NU9LboMwEF13TvGUDXagkQ2mSVB8EpoFAUMtiEFAo@T01FbbzWh@7ze91q/RZadp3rbGtGiZS6yWSa0FLwi2Ra21K17WDA3BDGFxcf6CdpzRwzrMlesMk4l7r2MZQAiwm3Ws54d6/HYri2TEtbaoXIM67i//jGjn8f6rGXvNuOfU6aG635oKz2IwjpX7lj35lW9Bzga53W4nAUlpKBkgSAEp5WGUwndS4YPkGUdKBaSgNIdUlGXIUlIS6khKIc8pFzgpypX/8fAzZJZ67sMyDdY7/nSRz/JWLYuZV3SMPQpd7u/VxKxbE9i/P@69leLq0z1KeaVptiHuapZ1wRTATcS3Hw)
]