2

For which $n$ it is possible to arrange the integers $1$, $1$, $2$, $2$, $\ldots$, $n$, $n$ in some order such that for all $i=1,2,\ldots,n$ between the two copies of $i$ there are exactly $i$ numbers?

This problem arose from a discussion with a friend. We have no idea about $n\equiv 0, 3 \pmod 4$ (apart from that it works up to $n=7$ or maybe $n=8$) but here is a proof that $n\equiv 1,2\pmod 4$ are not possible.

If the arrangement is $a_1 \ a_2 \ a_3 \dots a_{2n}$, put a comma between each two consecutive $a_i$-s. We double-count the number of pairs $(i, \mbox{comma})$ where the comma lies somewhere between the two copies of $i$. On one hand, there are $i$ numbers between the two $i$-s and hence $i+1$ commas, so overall the number of pairs is $2 + 3 + \cdots + n + (n+1) = \frac{n(n+3)}{2}$. On the other hand, there are $2n-1$ commas, so say that there are $n$ in odd positions and $n-1$ in even positions - each comma in odd position has an odd number of pairs around it and each comma in even position has an even number of pairs around it (to see this, start from the first comma which has $1$ pair and observe that each one after changes its number of pairs by $1$, up or down), so the overall amount of pairs has the same parity as $n$. In particular, $\frac{n(n+3)}{2} \equiv n \pmod 2$, i.e. $n^2 + n \equiv 0 \pmod 4$, which does not hold for $n\equiv 1,2 \pmod 4$.

Ideas on how could one proceed (constructively?) for $n\equiv 0,3 \pmod 4$? Any help appreciated!

DesmondMiles
  • 2,714
  • 2
    Just for clarity, bad to reuse the variable $i$ for the index, when you've asked a question using $i$ to mean the values. – Thomas Andrews Oct 24 '22 at 22:21
  • 1
    https://math.stackexchange.com/questions/3552702/assume-that-a-n-1-1-2-2-n-n-how-to-reorder-these-2n-numbers-such – RobPratt Oct 25 '22 at 01:39
  • another link to feed the algorithm: https://math.stackexchange.com/questions/4283324/find-out-whether-this-sequence-can-be-obtained-in-this-particular-order/4283353#4283353 – JMoravitz Oct 25 '22 at 01:53
  • Here is an answer for $n=8:$

    $$2672485364735181$$

    – Thomas Andrews Oct 25 '22 at 19:46
  • A python script found an answer for $n=11:$ $$7, 8, 6, 10, 11, 9, 5, 3, 7, 6, 8, 3, 5, 4, 10, 9, 11, 2, 4, 1, 2, 1$$ and $n=12:$ $$8, 9, 7, 11, 12, 10, 5, 6, 4, 8, 7, 9, 5, 4, 6, 11, 10, 12, 2, 3, 1, 2, 1, 3 $$ – Thomas Andrews Oct 25 '22 at 21:02
  • You can start to see certain patterns, like $k,k+1,k-1$ followed by $k-2$ spots then $k,k-1,k+1.$ My program brute forces it and so is unaware of patterns like this, these are just the first answers that come up. – Thomas Andrews Oct 25 '22 at 21:02
  • An answer for $24$ is interesting, because it ends with an answer for $7,$ which might give a hint to solving in general: $$16, 17, 15, 18, 19, 22, 24, 12, 23, 20, 10, 21,\ 13, 9, 14, 11, 8, 16, 15, 17, 12, 10, 18, 9, \19, 8, 13, 11, 22, 14, 20, 24, 23, 21,\ 5, 3, 6, 4, 7, 3, 5, 2, 4, 6, 2, 1, 7, 1$$ – Thomas Andrews Oct 25 '22 at 21:24
  • If $k,n\equiv 0,3\pmod 4$ and $3k\leq n-3$ then some experimentation shows there is often (always, in experimentation) a solution for $n$ which starts with $n.$ And it is an efficient way to look for answers for larger $n.$ – Thomas Andrews Oct 26 '22 at 00:28
  • For example, when $n=51,$ we get a solution starting with $k=12:$ $$10, 11, 12, 8, 13, 15, 16, 14, 7, 9, 6, 10, 8, 11, 5, 12, 7, 6, 13, 9, 5, 15, 14, 16, 2, 3, 4, 2, 1, 3, 1, 4, 34, 35, 33, 36, 37, 32, 38, 31, 39, 40, 30, 41, 45, 47, 48, 43, 50, 51, 49, 46, 44, 42, 29, 19, 22, 25, 17, 18, 20, 24, 26, 23, 27, 28, 21, 34, 33, 35, 32, 31, 36, 30, 37, 19, 17, 38, 18, 22, 39, 20, 40, 25, 29, 41, 24, 23, 21, 26, 45, 43, 27, 47, 28, 48, 42, 44, 46, 50, 49, 51$$ – Thomas Andrews Oct 26 '22 at 00:29
  • In particular, if you have a solution for $n\equiv 0,3\pmod 4,$ there might be a way to solve for $n'=3n+3,$ starting with the $n$ example. If you do so, the left elements of each pair has to occupy the spaces $2n+1,2n+2,\dots,n'+n=4n+3.$ That puts some tight restrictions on what labels can go in each. From the scripts there always seems to be a way, but I haven found a pattern. Essentially, it requires a bijection $$f:{1,2,3,\dots,2n+3}\to{n+1,n+2,\dots,3n+3}$$ such that $4n+4\leq f(i)+i\leq 6n+6$ and $i\mapsto i+f(i)$ is also one-to-one. – Thomas Andrews Oct 26 '22 at 01:00
  • Sorry the $n=51$ case starts with $k=16.$ – Thomas Andrews Oct 26 '22 at 01:04

1 Answers1

2

I can prove there are infinitely many $n$ for which there are solutions.

Specifically, if we have a solition for $n,$ we can get a solution to $n'=3n+3.$

We will do so by proving that there is a sequence of length $4n+6$ of pairs of numbers from $n+1$ to $3n+3$ which satisfy your property.

We start with the sequence $$(2n+2,2n+3,\dots,3n+3,n+1,\dots,2n+1)$$ This entirely determine the rest of the sequence.

For example, $n=3$ then we get a complete example:

$$(8,9,10,11,12,4,5,6,7,\\8,4,9,5,10,6,11,7,12)$$

The second half is the alternating interlaced sequence of the $(8,9,10,11,12)$ and $(4,5,6,7).$

So if we can solve for $n,$ we can append the solution to this and get a solution for $3n+3.$

Since we have solutions for $n=3,$ we have solutions for $12,$ so we have solutions for $39,$ so we have solutions for $120,$ etc. We have a way to create solutions for infinitely many $n.$


It seems, from some Python scripting experiments, that if $N\equiv 0,3\pmod 4$ and $n$ is the largest integer $\equiv 0,3\pmod 4$ with $3n+3\leq N,$ there is an answer for $N$ beginning with an answer for $n.$ But I've only shown the above case, where $3n+3=N,$ which is when $N\equiv 0,3\pmod {12}.$

But you might be able to do something similar, likely a little more complex, for $N\equiv 4,7,8,11\pmod{12}.$


A different way of deriving that $n\equiv 0,3\pmod 4$ requirement. And maybe an explanation why the other cases are hard.

We are going to view a circular version of the problem. If there is an answer to your problem, there is an answer to the circular problem, but not vice versa.

If we have the cyclic group $G=\mathbb Z/2n\mathbb Z$ we are seeking seeking distinct elements $c_1,\dots, c_n$ such that $c_i+i+1\neq c_j$ and $c_i+i+1\neq c_j+j+1$ for any $i\neq j.$

Then $$\sum_i(2c_i+i+1)=\frac{n(n+3)}2+2\sum c_i\equiv \sum_{k=0}^{2n-1} k=n(2n-1)\equiv n\pmod {2n}$$

This means $\frac{n(n+3)}{2}$ and $n$ must have the same parity, so $\frac{n(n+1)}{2}$ must be even, so we get your result that $n\equiv0,3\pmod 4.$

So you can't solve this problem when $n\equiv 2,3$ even if we allow more freedom of a circular set of pairings.

We also get, when $n\equiv 0,3\pmod 4$ that:

$$\sum c_i\equiv -\frac{n(n+1)}{4}\pmod{n}$$

When $n\equiv 0\pmod 4,$ that means $\sum c_i\equiv -\frac n4\pmod n.$

When $n\equiv 3\pmod 4,$ we get $\sum c_i\equiv 0\pmod n.$


The uniqueness condition is equivalent to requiring $c_i-c_j\neq 0,-(i+1), j+1, j-i.$


I would not be surprised if there was always a circular case for $n\equiv 0,3,$ but that sometimes there is no non-circular case. That would explain why it is hard to prove relatively quickly.


For example, if, rather than $i$ between the two $i$s, we required $f_i$ between them, then we'd need $\sum f_i$ to be even.

But when all $f_i=2,$ we can solve the circular case for any $n>1,$ but we can only solve the non-circular case when $n$ is a multiple of $3.$


Actually, even in the straight question, if $c_i$ is the position of the left-most $i,$ where the positions are labeled $0,1,\dots,2n-1,$ then you get:

$$n+\frac{n(n+1)}{2}+2\sum c_i = n(2n-1)$$ or $$\sum c_i =n^2-n-\frac{n(n+1)}{4}=\frac{n(3n-5)}{4}.$$

Using this, by hand, I got an example when $n=7:$

$$57263254376141$$

And here is an answer for $n=8:$

$$2672485364735181$$

Thomas Andrews
  • 177,126