# Determine How many Wheels There Are

## Non-math explanation

This is an explanation that is meant to be approachable regardless of your background. It does unfortunately involve some math, but should be understandable to most people with a middle school level of understanding

A pointer sequence is any sequence such that $$\a(n+1) = a(n-a(n))\$$.

Lets pick apart this formula a little bit to understand what it means. This just means to figure out the next term in the sequence we look at the last term, take that many steps back and copy the term we find. For example if we had the sequence so far to be

... 3 4 4 4 3 ?


We would take 3 steps back from 3

... 3 4 4 4 3 ?
^


making our result 4.

Now normally we play this game on a tape that is infinite in both directions, but we can also play it on a wheel where after a certain number of steps we get back to the beginning of the sequence.

For example here is an visualization of the sequence [1,3,1,3,1,3]

Now we might notice that any number, $$\x\$$ in a wheel that exceeds the number of cells in the wheel, $$\n\$$, might as well be $$\x\$$ modulo $$\n\$$ because every complete circuit around the wheel is the same as doing nothing. So we will only consider wheels with all members being less than the size of the wheel.

## Math explanation

A pointer sequence is any sequence such that $$\a(n+1) = a(n-a(n))\$$. Usually these are defined from the integers to the integers, however you might notice that the only things needed in this definition are a successor function and an inverse function. Since all cyclic groups have both of these we can actually consider pointer sequences on any cyclic groups.

If we start looking for these types of functions we will notice that for each function there are a couple of similar functions. For example on $$\\mathbb{Z}_3\$$ the following 3 are all functions that fit our requirements.

f1 : [1,2,2]
f2 : [2,1,2]
f3 : [2,2,1]


(Here a list is used to represent a function to get the result just index the list by the input)

We might notice that these functions are all "rotations" of each other. To formalize what I mean by rotation, a function $$\b\$$ is a rotation of $$\a\$$ iff

$$\ \exists n : \forall m : a(m+n) = b(m) \$$

We can actually show that if $$\a\$$ is a pointer sequence every rotation of $$\a\$$ is also a pointer sequence. Thus we will actually consider any sequences that are rotations of each other to be equivalent.

Given $$\n\$$ as input output the number of pointer sequences that have size $$\n\$$.

This is so answers will be scored in bytes with less bytes being better.

## Testcases

Currently these testcases are lacking a bit, I have a computer program to generate these but it is inordinately slow at doing so. If anyone would like to contribute larger testcases (that they can verify correct) they are free to do so. Below some tests is a list of all the functions that I found, this might be useful for debugging. I can't add these for the larger ones because of character limits.

If you want the code I used to generate these here it is

1 -> 1
[[0]]
2 -> 2
[[1,1],[0,0]]
3 -> 4
[[2,2,2],[2,2,1],[1,1,1],[0,0,0]]
4 -> 7
[[3,3,3,3],[3,3,3,2],[2,2,2,2],[3,3,3,1],[3,1,3,1],[1,1,1,1],[0,0,0,0]]
5 -> 12
[[4,4,4,4,4],[4,4,4,4,3],[3,3,3,3,3],[4,4,4,4,2],[4,3,4,4,2],[2,2,2,2,2],[4,4,4,4,1],[4,3,4,4,1],[4,4,2,4,1],[4,4,1,4,1],[1,1,1,1,1],[0,0,0,0,0]]
6 -> 35
[[5,5,5,5,5,5],[5,5,5,5,5,4],[5,5,4,5,5,4],[4,4,4,4,4,4],[5,5,5,5,5,3],[5,4,5,5,5,3],[5,5,5,3,5,3],[5,3,5,3,5,3],[3,3,3,3,3,3],[5,5,5,5,5,2],[5,4,5,5,5,2],[5,3,5,5,5,2],[5,5,4,5,5,2],[5,5,2,5,5,2],[5,5,2,5,2,2],[5,3,2,5,2,2],[5,2,2,5,2,2],[4,2,2,4,2,2],[2,2,2,2,2,2],[5,5,5,5,5,1],[5,4,5,5,5,1],[5,3,5,5,5,1],[5,5,4,5,5,1],[5,5,2,5,5,1],[5,5,1,5,5,1],[5,5,5,3,5,1],[5,3,5,3,5,1],[5,5,5,2,5,1],[5,5,5,1,5,1],[5,3,5,1,5,1],[5,1,5,1,5,1],[3,1,3,1,3,1],[2,2,1,2,2,1],[1,1,1,1,1,1],[0,0,0,0,0,0]]
7 -> 80
[[6,6,6,6,6,6,6],[6,6,6,6,6,6,5],[6,6,6,5,6,6,5],[5,5,5,5,5,5,5],[6,6,6,6,6,6,4],[6,5,6,6,6,6,4],[6,6,6,5,6,6,4],[6,6,6,6,4,6,4],[6,5,6,6,4,6,4],[6,4,6,6,6,4,4],[4,4,4,4,4,4,4],[6,6,6,6,6,6,3],[6,5,6,6,6,6,3],[6,4,6,6,6,6,3],[6,6,5,6,6,6,3],[6,6,4,6,6,6,3],[5,6,6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,3,1],[3,5,7,1,7,5,3,1],[3,5,3,1,3,5,3,1],[3,3,3,1,3,3,3,1],[3,1,3,1,3,1,3,1],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0]]
9 -> 1049
10 -> 4304


Last case calculated by @HyperNeutrino

• +1 for a really well documented challenge although I still don't fully understand it. Commented Oct 23, 2017 at 18:04
• @ElPedro What are you still unsure of? Perhaps I can help make this question more clear. Commented Oct 24, 2017 at 2:16

# Jelly, 18 17 bytes

J_ịṙ1⁼
ṗṙ€RṂ€QÇ€S


Try it online!

### How it works

ṗṙ€RṂ€QÇ€S  Main link. Argument: n

ṗ           Cartesian power; yield all vectors of n elements of [1, ..., n].
R        Range; yield [1, ..., n].
ṙ€         Rotate each vector 1, ..., and n units to the left.
Ṃ€      Take the minimum of each array of rotations of the same vector.
Q     Unique; deduplicate the resulting array.
Since each vector is replaced by its lexicographically minimal
rotation, no resulting vector will be a rotation of another vector.
Ç€   Map the helper link over the remaining vectors.
Vectors that represent pointer sequences map to 1, others to 0.
S  Take the sum.

J_ịṙ1⁼      Helper link. Argument: v = (v1, ..., vn)

J           Indices; yield [1, ..., n].
_          Subtract v, yielding [1 - v1, ..., n - vn].
ị         Index into v, yielding [v(1 - v1), ..., v(n - vn)].
ṙ1       Rotate the result one unit to the left.
⁼      Compare the result with v.


# Python 2, 162156152146 143 bytes

lambda n:len({min(l[i:]+l[:i]for i in R(n))for l in product(*[R(n)]*n)if all(l[-~i-n]==l[i-l[i]]for i in R(n))})
from itertools import*
R=range


Try it online!

More or less brute force:

• Generates all permutations product(r,repeat=n)
• Checks valid lists. all(l[-~i-n]==l[i-l[i]]for i in r)
• Generates a set of the minimum (lexicographical) rotation of the valid lits min(l[i:]+l[:i]for i in r)

Recursive function that short circuits a bit:

This version is longer, but is able to calculate f(10) in ~19 secs on tio.run

On my machine, I've found:

• f(11) = 16920
• f(12) = 78687

# Python 2, 209 bytes

lambda n:len(g(n,(-1,)*n))
r=range
g=lambda n,a,j=0:set()if any(len({-1,a[-~i-n],a[i-a[i]]})>2for i in r(j))else set.union(*[g(n,a[:j]+(i,)+a[j+1:],j+1)for i in r(n)])if j<n else{min(a[i:]+a[:i]for i in r(n))}


Try it online!

Explanation:

f=lambda n:len(g(n,(-1,)*n)) #calls the recursive function, and gets length.
#The initial circle is all -1, and is built recursively
r=range
g=lambda n,a,j=0:
#if any of the indexes so far break the pointer rule (ignored if 'empty'), stop recursion.
if any(len({-1,a[-~i-n],a[i-a[i]]})>2for i in r(j))
return set()
else
if j<n:
#recursively call g with a+ all numbers in range ie.(a+[0], a+[1], ..)
return set.union(*[g(n,a[:j]+(i,)+a[j+1:],j+1)for i in r(n)])
else # if recursion depth == n, we are done. Return the smallest (lexicographically) rotation.
return {min(a[i:]+a[:i]for i in r(n))}

• Surely Python's array indexing means you can drop the %n (and then a few parentheses)? Commented Oct 24, 2017 at 8:25
• Commented Oct 25, 2017 at 12:30

# CJam, 37

ri:M_m*{:XM,Xfm<:e<=M{(_X=-X=}%X=&},,


Try it online

Pretty much brute force, and it feels kinda clumsy. It gets very slow after 6. Replace the last comma with a p to print the wheels.

# Pyth, 28 bytes

l{mS.>LdQf!fn@ThY@T-Y@TYUQ^U


Test suite

First, we generate all sequences of the appropriate length with the appropriate elements. Second, we check whether there are any pointer failures. Third, map to all sorted rotations. Fourth, deduplicate and count.

# Haskell, 117 112 104 bytes

f k|x<-[1..k]=sum[1|y@(h:t)<-mapM(x<$f)x,t++[h]==[y!!mod(n-a)k|(n,a)<-zip x y],and[y<=drop n y++y|n<-x]]  Brute force, so pretty slow for large inputs. Try it online! -5 bytes thanks to Laikoni. -5 bytes thanks to Ørjan Johansen. • and[y<=drop i y++take i y|i<-x] saves some bytes. Commented Oct 24, 2017 at 19:03 • @Laikoni So it does, thanks! Commented Oct 24, 2017 at 19:07 • (1) x<$f is one byte shorter than \_->x. (2) Thanks to laziness, ndropcycle y saves 4 bytes over drop n y++take n y. Commented Oct 25, 2017 at 7:36
• @ØrjanJohansen Thanks, the <$ trick is nice. drop n y++y turns out to be even shorter for the second hint. Commented Oct 25, 2017 at 8:09 • Hm that's almost tails, so 4 more with a variant of the standard trick: all(y<=)$scanr(:)y y. Commented Oct 25, 2017 at 18:53

# Wolfram Language (Mathematica), 150 123 bytes

nCount[Tuples[r=Range@n-1,{n}],l_/;l==Sort[l~RotateLeft~#&~Array~n][[1]]&&And@@(!1!-!0//.!a_:>l[[Mod[#+a,n,1]]]&/@r)]


Try it online!

-27 bytes thanks to att.

Explanation from 150 byte version:

p=Part[#,Mod[#2,Length@#,1]]&;            -helper function to take part of circular list

n|->
Count[                                  -count all the
Tuples[Range@n-1,{n}],                  -possible sequences
_?(l|->                                 -where
l==Sort[Array[RotateLeft[l,#]&,n]][[1]]  -the sequence is the first of all rotations of that sequence
&&                                       -and
And@@Array[p[l,#+1]==p[l,#-p[l,#]]&,n]   -the pointer property holds for all elements in that sequence
)]

• In lieu of |->,  (\[Function]) is recognized by TIO, and has the same byte count.
– att
Commented Oct 16, 2021 at 2:49
• 123 bytes. The first box (after the first n) is \[Function], and the second (after !1) is \[Xnor].
– att
Commented Oct 16, 2021 at 4:00