J, 56 bytes
b=:monad define
{:#:(+/(0|.y)*.(-.1|.y)*.(2|.y)*.3|.y)
)
Try it online!
Usage:
> echo b 1 0 1 0 1 0 1 0 1 0
0
> echo b 1 0 1 0 1 0 1 1 0 0
1
This is a terrible solution in terms of score, I'm aware. This is both my first time code golfing and my first time using J, and my interest in this problem was the finding the function part, not the golfing. Consider the golfing as just an excuse for me to post my solution to what is in spirit a math puzzle.
How does it work?
The function I wrote takes a list of 10 Boolean values, and counts the number of (cyclic) occurrences of the pattern 1011, mod 2. ("Cyclic" means that e.g. if bits 9, 0, 1, 2 are 1 0 1 1 respectively, then the pattern is considered to have occurred at position 9. In other words, indices modulo 10.)
The program accomplishes this by basically doing a bitwise AND of copies of the string rotated by 0, 1, 2, and 3 positions, of which the one rotated by 1 position was also bitwise negated, then counting the 1s in the resulting string and extracting the final bit of that number.
Clearly, this function is invariant under rotations. To show that it's not invariant under any permutation that isn't a rotation, I'll show that there's a 1011 pattern that doesn't get preserved under the permutation; then an input consisting of just that one 1011 pattern and all 0s otherwise would return 1 without the permutation, but 0 with it.
Consider a permutation P of {0, 1, 2, ..., 9}. Suppose there's a 1011 pattern at the 0th position, and everything else is all zeros. Then, in order to preserve it, there must exist an n such that 0, 2, 3 are mapped under P to some permutation Q of {n, n + 2, n + 3}. Then we can show that, in each of the six cases,
- (i), 1 must be mapped to n + 1, otherwise some 1011 pattern would be destroyed;
- (ii), all permutations Q that aren't the identity permutation would also cause some 1011 pattern to be destroyed, if we assume (i).
For both points, our "culprit" will be two positions at a distance of 3 or less which are mapped to positions at a distance of 4 or more. Since our test patterns are ones that have only a single 1011 pattern and all zeros otherwise, and so all 1s in such patterns have a distance of 3 or less to each other, it will be impossible for P to preserve 1011 patterns if we can show it maps even one pair with distance 3 or less to a pair with distance 4 or more. That's because if two 1s end up at distance 4 or more, and we only have three 1s to work with, we can't assemble a 1011 pattern anymore. This distance argument works even though the ten positions are cyclic because 4 < 10/2: if something is closer from the left side and still 4 or more spots away, it can't actually secretly be within 3 spots away from the right side, because then it'd be closer from the right side.
This basically breaks the proof down into six cases. Illustratively I'll work through the proof for the case Q = {n, n + 3, n + 2}:
- (i) Suppose 1 isn't mapped to n + 1, but instead somewhere outside the 1011 pattern. If it's closer to the pattern from the right, i.e. it's mapped to n + 4 or more, then since 0 is mapped to n, 0 and 1 would be mapped to a distance of 4 or more. If it's closer from the left, i.e. n - 1 or less, then 2 is mapped to n + 3, and so 1 and 2 would be mapped to a distance of 4 or more.
- (ii) Now that it's established that 1 is mapped to n + 1, let's continue to enforce what is mapped where by using the 1011-preserving property. A pattern at position 1 would map its starting 101 to 110, which, to preserve 1011, must mean that position 4 (which now contains the only remaining 1) must map to n - 1. Then a pattern at position 2 would map its starting 101 to 1..01, where two of the 1s are at distance 4, contradiction. In general, for each of the cases where Q isn't the identity, (ii) always takes at most two deduction steps to run into a contradiction -- and they always consider patterns at positions 1 and 2, except the case {n + 3, n, n + 2}, which for some reason instead required considering patterns at positions -1 and -3 (i.e. 9 and 7).
If you found that extremely verbose and at the same time way too abbreviated and convoluted, I'm with you. I'm finding it nearly impossible to carry out this proof in a way that reads well without going on for far too long. Instead, I carried out the full proof in a much neater way as a proof without words -- by encoding it into six pretty dot diagrams:
In the center of each is the permutation Q being considered, but with the rotation effect removed, and with 1 already being assumed to map to n + 1. The tiny dots at the very bottom and the arrows at the very top represent step (i), finding pairs of positions close enough that map to positions too far away. All the other dots above and below represent step (ii), where, using 1011 patterns at positions other than 0, we deduce more about what gets mapped where, and finish by finding a pair of 1s mapped too far away, marked with a brace. The conclusions in (ii) happen outward from the center in a "spiral" order: the first additional use of the 1011-preserving property happens one level below the central permutation; its conclusions, one level above it; the next use is two levels below the permutation; the conclusions from that are two levels above it, and so on.
In each case, we're able to do step (i), and in each case except when Q is the identity, also step (ii). Thus all of 0, 1, 2, 3 must map by the same offset, and then by considering a pattern starting at position 1, it follows that 4 too must map by the same offset, and so on, until we conclude that the whole mapping P is a rotation.
A little addendum
My first solution idea that got somewhat far was to count the occurrences of the simpler pattern 01, and I started working on a proof that rotations are the only permutations that preserve adjacency, so that if a permutation wasn't a rotation, then it would map some pair 11 onto two disjoint 1s, thus increasing the count of 01 patterns from 1 to 2 if the rest of the input is all zeros. However, I found that the permutations that preserve adjacency are not just rotations: they're precisely the rotations and reflections. In fact it's quite easy to see that we can't exclude reflections, because the number of cyclic occurrences of 01 will always be equal to the number of cyclic occurrences of 10. So if anyone ever submits an identical problem except now the function must be invariant under reflections too, there's a solution to that.
The smallest bit pattern that doesn't play along with reflections in this way (i.e. it's not mirror-symmetric itself, and it doesn't occur exactly as often as its mirror image) must be 4 bits long. I picked 1011 and rolled with it, but obviously 1101, 0100, and 0010 (at least) would work equally well.
"0110100011"
? \$\endgroup\$