How many aperiodic binary strings of length 23 exist?
1
and
0
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.
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
Just clarify. By the definition, is the string 1 0 1 0 1 0 1 0 1 0 1 0 1 aperiodic?
Our first clue is that there are at-most 2 n strings of length n .
Now, notice two more things.
Every periodic string of length n has been made up by repetition of strings of lengths that divide 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 |
|
When calculating periodic n, knowing the cases when n ≡ 0 ( m o d 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).
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.
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.
Problem Loading...
Note Loading...
Set Loading...
Note that there are 2 2 3 = 8 3 8 8 6 0 8 binary strings of length 2 3 . We will count the number of periodic binary strings of length 2 3 and subtract from this number.
If a string of length n is periodic with a string of length m as its building block (the one that is repeated several times), then m ∣ n . Since the only proper divisor of 2 3 is 1 , the only periodic binary strings of length 2 3 are those whose building block is a binary string of length 1 . There are only two binary strings of length 1 ( 0 and 1 ), so the only periodic binary strings of length 2 3 are 0 0 0 … 0 and 1 1 1 … 1 . There are 8 3 8 8 6 0 8 − 2 = 8 3 8 8 6 0 6 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 2 3 ! 2 3 , instead of a simple prime number.