Aperiodic Binary Strings

How many aperiodic binary strings of length 23 exist?

  • A binary string is a string consisting of only 1 and 0
  • A string is periodic if there is a shorter string which can be concatenated two or more times to obtain the periodic string. A string that is not periodic is aperiodic


The answer is 8388606.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Ivan Koswara
Nov 28, 2015

Note that there are 2 23 = 8388608 2^{23} = 8388608 binary strings of length 23 23 . We will count the number of periodic binary strings of length 23 23 and subtract from this number.

If a string of length n n is periodic with a string of length m m as its building block (the one that is repeated several times), then m n m|n . Since the only proper divisor of 23 23 is 1 1 , the only periodic binary strings of length 23 23 are those whose building block is a binary string of length 1 1 . There are only two binary strings of length 1 1 ( 0 0 and 1 1 ), so the only periodic binary strings of length 23 23 are 000 0 000\ldots 0 and 111 1 111\ldots 1 . There are 8388608 2 = 8388606 8388608 - 2 = \boxed{8388606} strings remaining, which are necessarily aperiodic.


Tip to OP: If you want to force a program to compute it, put some massive, composite number, like 23 ! 23 23!^{23} , instead of a simple prime number.

Moderator note:

How would we deal with a simple composite number (say the product of 2 distinct, but large, primes)?

How would we deal with a simple composite number (say the product of 2 distinct, but large, primes)?

Answer: Try Ivan's problem

Calvin Lin Staff - 5 years, 6 months ago

Just clarify. By the definition, is the string 1010101010101 1010101010101 aperiodic?

Janardhanan Sivaramakrishnan - 5 years, 6 months ago

Log in to reply

It is aperiodic.

Ivan Koswara - 5 years, 6 months ago

Our first clue is that there are at-most 2 n 2^n strings of length n n .

Now, notice two more things.

Every periodic string of length n n has been made up by repetition of strings of lengths that divide n n . However, we should only count the aperiodic smaller strings because the periodic strings already consist of them.

This will be clear in the program.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
periodic :: Integer -> Integer
aperiodic :: Integer -> Integer

aperiodic 1 = 2
aperiodic n = 2^n - (periodic n)

periodic 1 = 0
periodic n = sum $ map aperiodic [i | i<-[1..n-1], n `mod` i == 0]

main = putStrLn $ show (aperiodic 23)

Moderator note:

When calculating periodic n, knowing the cases when n 0 ( m o d i ) n \equiv 0 \pmod i could help simplify the code.

Are you sure about the code? When calculating strings of length 6, will you be triple-counting the string 111111? It seems to appear in the summation as aperiodic(1), aperiodic(2), aperiodic(3).

Calvin Lin Staff - 5 years, 6 months ago

Log in to reply

111111 only appears in aperiodic(1). 11 or 111 are not aperiodic strings.

Actually, as @Ivan Koswara has shown, using a prime number here has made this a trivial problem.

Agnishom Chattopadhyay - 5 years, 6 months ago

Log in to reply

Ah yes, my bad. I mixed up the two of them as I was reading through your solution. Yup, looking at aperiodic strings is sufficient.

Calvin Lin Staff - 5 years, 6 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...