user
**Gosper's Hack** is an efficient method of computing the next higher integer with the same number of set bits (Hamming weight). It was invented by Bill Gosper. The algorithm is widely used in combinatorics for enumerating combinations.

Task

Write a function or procedure to compute the next higher integer with the same number of set bits as a given positive integer, using Gosper’s Hack.

Show the result of applying it ten times to each of the numbers 1, 3, 7, and 15.

Reference

* Gosper's Hack explained
assistant
```
sub gosper ($x) {
    my $c = $x +& -$x;
    my $r = $x + $c;
    ((($r +^ $x) +> 2) / $c) +| $r
}

for 1, 3, 7, 15 -> $start {
    my @g = $start, { gosper $_ } … *;
    say @g[^11].fmt('%8d');
    say @g[^11].fmt('%08b');
    say '';
}

```

Output:

```
       1        2        4        8       16       32       64      128      256      512     1024
00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 100000000 1000000000 10000000000

       3        5        6        9       10       12       17       18       20       24       33
00000011 00000101 00000110 00001001 00001010 00001100 00010001 00010010 00010100 00011000 00100001

       7       11       13       14       19       21       22       25       26       28       35
00000111 00001011 00001101 00001110 00010011 00010101 00010110 00011001 00011010 00011100 00100011

      15       23       27       29       30       39       43       45       46       51       53
00001111 00010111 00011011 00011101 00011110 00100111 00101011 00101101 00101110 00110011 00110101

```