r/AskProgramming • • Jun 05 '26

Algorythm for rotationally asymetrical binary numbers

Hello! I am struggling to code or find a programm that can automatically find all rotationally asymetrical binary numbers in a given digits range. It's been two weeks that I am searching now, do you have any advice or does anyone know how to do it?

3 Upvotes

32 comments sorted by

View all comments

Show parent comment

2

u/SergeAzel Jun 06 '26

So after realizing I just told you to use a DFT, I considered more deeply on how to categorize. One step forward, I would say, would be to have the ability to count the total number of sets unique up to rotation.

Then I realized its quite simple.

I'm going to be misusing some terms:

"State" is going to mean a unique bit state, 01010 being considered different from 00101.
"N-Cycle" is going to mean "number of bits needed to rotate before it ends up in the same state again".
"Set" in this case is going to refer to a set of states where, applying a cycle to any of those states gives us another state in that set, aka all of the "rotationally symmetric" states.

Lets say we have 5 bits, for 2^5 total states. 5 is prime, so there's only two unique cycles we could get out of it: a 1-cycle and a 5-cycle.

We only have two 1-cycles, and that's obviously 00000 and 11111. Everything else is a 5-cycle. This means that, if we remove the two one-cycles from the total states, we can divide what's left by 5, to get the total number of "sets" of 5-cycles.

So, simply, 2^5 = 32, minus 2 leaves us with 30 states, divide by 5 leaves us with 6 sets of 5-cycles. Those being:

00001
00011
00101
and their mirrors:
11110
11100
11010

Now, for 5 bits this is somewhat trivial, but we can apply this strategy to something bigger like 15 bits.

For prime numbers p, you can tell the total number of states as being:

15 has four factors: 1, 3, 5, and 15.
This means we'll have 1-cycles, 3-cycles, 5-cycles, and 15-cycles only.

To get the total number of unique sets, we just add up the sets of 1 cycles, 3 cycles, 5 cycles, and 15 cycles.

2^15 gives us the total number of unique states.
We know trivially there's 2 1-cycle states.

We also know there's (2^5 - 2) = 30 unique 5-cycle states.
By this pattern we can say there's (2^3 - 2) = 6 unique 3-cycle states.

This gives us a total of (2 + 30 + 6) = 38 states that aren't 15 cycles.
This means there's a total of 2^15 - 38 = 32730 states that are 15 cycles. Which, thankfully, is divisible by 15, making 2182 sets that are 15 cycles.

Then, sum up the total number of sets by cycle:

(2 / 1) = 2 sets of 1 cycles

(6 / 3) = 2 sets of 3 cycles

(30 / 5) = 6 sets of 5 cycles

(32730 / 15) = 2182 sets of 15 cycles

Giving a total of 2192 sets down to cycle uniqueness of 15 bits.

Pretty sure a mathematician would say this is all trivial number theory, but I'm not an expert at math.

1

u/Used_Astronomer6483 Jun 06 '26

It is really interesting, I do not have thought about a way to count them, eventhough, now that I see it, I find it really useful. Thank you!