Weighted Popcount

Popcount with weights?

Weighted Popcount Distribution

Problem Statement

Generate a 10-bit vector where the number of 1s (popcount/population count) is uniformly distributed across all possible counts from 1 to 10.

Each possible popcount value (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) should have an equal 10% probability of being generated.

This constraint ensures fair distribution of bit patterns across different Hamming weights.

Constraints

  • Vector size: 10 bits
  • Popcount range: 1 to 10 (exactly one 1, two 1s, ..., or all ten 1s)
  • Distribution: Each popcount value has exactly 10% probability (equal weighting)
  • Valid patterns: Any 10-bit vector with 1-10 ones

Examples

Example 1:

1111100000 (or any other arrangement with exactly 5 ones)
Explanation: Exactly 5 bits are set to 1

Example 2:

0000000001 (or 0000000010, or any single bit set)
Explanation: Exactly 1 bit is set to 1, 9 bits are 0

Example 3:

1111111111
Explanation: All 10 bits are set to 1

Example 4:

- Sample 1: 1010101010 (popcount = 5)
- Sample 2: 1111111111 (popcount = 10)
- Sample 3: 0000000001 (popcount = 1)
- Sample 4: 1111000000 (popcount = 4)
- Sample 5: 1110000000 (popcount = 3)
...running 1000 samples...
Output: Distribution shows roughly 10% samples for each popcount value 1-10
Explanation: The statistical distribution validates equal weighting

Example 5:

1111111111 (popcount = 10)
Valid (popcount = 10)
Explanation: 10 ones, within the allowed range [1:10]

Example 6:

0000000000 (popcount = 0)
Invalid
Explanation: Popcount 0 is not in the allowed range [1:10]

Loading the interactive workspace...