Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
As soon as the Elves get bored with the last week's game, Bin comes up with a new game. The rules are similar, except the Elves are supposed to say the numbers that have its "left side" equal to its "right side" when written in binary. The "left" and "right" sides are defined as the first and last floor(k/2)
bits, where k
is the total number of bits.
Some examples:
- The numbers that are just two copies joined together, such as 3 (
11
), 10 (1010
), 15 (1111
), ... are valid. This sequence is A020330. - 1 (
1
) is valid because its left and right parts are both empty, and as are 18 (10010
) and 22 (10110
) because their left and right are both10
. - 17 (
10001
) is not valid because10
!=01
.
You can use any of sequence I/O methods:
- Output the corresponding sequence infinitely
- Given the index
k
(may be 1- or 0-indexed), output thek
th number in the sequence - Given
k
, output the firstk
numbers of the sequence
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
1, 3, 5, 7, 10, 15, 18, 22, 27, 31, 36, 45, 54, 63, 68, 76, 85, 93, 102, 110,
119, 127, 136, 153, 170, 187, 204, 221, 238, 255, 264, 280, 297, 313, 330, 346,
363, 379, 396, 412, 429, 445, 462, 478, 495, 511, 528, 561, 594, 627, 660, 693,
726, 759, 792, 825, 858, 891, 924, 957, 990, 1023, 1040, 1072, 1105, 1137, 1170,
1202, 1235, 1267, 1300, 1332, 1365, 1397, 1430, 1462, 1495, 1527, 1560, 1592,
1625, 1657, 1690, 1722, 1755, 1787, 1820, 1852, 1885, 1917, 1950, 1982, 2015,
2047, ...
This sequence is not yet on OEIS.