Determine How many Wheels There Are

23

2

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]

Wheel

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 mod 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 Z3 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

equation 1

Now if we get a little bit of math involved here, 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.

Task

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 ->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,0,0,0,0,0,0]]
9 -> 1049
10 -> 4304

Last case calculated by @HyperNeutrino

Post Rock Garf Hunter

Posted 2017-10-23T17:27:32.867

Reputation: 55 382

1+1 for a really well documented challenge although I still don't fully understand it. – ElPedro – 2017-10-23T18:04:49.943

@ElPedro What are you still unsure of? Perhaps I can help make this question more clear. – Post Rock Garf Hunter – 2017-10-24T02:16:52.827

Answers

7

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.

Dennis

Posted 2017-10-23T17:27:32.867

Reputation: 196 637

5

Python 2, 162 156 152 146 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))}

TFeld

Posted 2017-10-23T17:27:32.867

Reputation: 19 246

Surely Python's array indexing means you can drop the %n (and then a few parentheses)? – Peter Taylor – 2017-10-24T08:25:13.283

143 bytes. – Jonathan Frech – 2017-10-25T12:30:21.823

3

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.

aditsu quit because SE is EVIL

Posted 2017-10-23T17:27:32.867

Reputation: 22 326

3

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.

isaacg

Posted 2017-10-23T17:27:32.867

Reputation: 39 268

3

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.

Zgarb

Posted 2017-10-23T17:27:32.867

Reputation: 39 083

and[y<=drop i y++take i y|i<-x] saves some bytes. – Laikoni – 2017-10-24T19:03:22.097

@Laikoni So it does, thanks! – Zgarb – 2017-10-24T19:07:57.880

(1) x<$f is one byte shorter than \_->x. (2) Thanks to laziness, n`drop`cycle y saves 4 bytes over drop n y++take n y. – Ørjan Johansen – 2017-10-25T07:36:58.207

@ØrjanJohansen Thanks, the <$ trick is nice. drop n y++y turns out to be even shorter for the second hint. – Zgarb – 2017-10-25T08:09:36.753

Hm that's almost tails, so 4 more with a variant of the standard trick: all(y<=)$scanr(:)y y. – Ørjan Johansen – 2017-10-25T18:53:28.373