2

For any positive integer $n$, let $f(n)$ be the number of permutations $a_1,\cdots, a_n$ of $1,\cdots, n$ so that $a_1=1$ and $|a_i-a_{i+1}|\leq 2$ for $1\leq i\leq n-1$. Find $f(2022)\pmod 3$.

Edit: apparently it makes more sense for the inequality to hold for $1\leq i\leq n-1$, whereas in the original source for this question, the inequality held for $2\leq i\leq n-1$. The original source is problem 12 from this problem set.

We have $f(1)=1, f(2)=1, f(3)=2$. $f(4) = 6.$ $f(5)$ does not count only those permutations where 2 and 5 are consecutive. There are $12$ such permutations, so $f(5) = 24-12 = 12.$ $f(6)$ does not count those permutations $p_{26}$ where $2$ and $6$ are adjacent, where $2$ and $5$ are adjacent, denoted $p_{25}$, or where $3$ and $6$ are adjacent, denoted $p_{36}$. Let $p_{526}$ denote the number of permutations where $2$ is adjacent to both 6 and 5, $p_{263}$ denote the number of permutations where 2 is adjacent to 6 and 3 is adjacent to 6, $p_{25,36}$ denote the number of permutations where 2 is adjacent to 5 and 3 is adjacent to 6, and let $p_{5263}$ denote the number of permutations where 2 is adjacent to 5 and 6 and 6 is adjacent to 3. One can use the inclusion-exclusion principle to deduce that $f(6) = p_{26}+p_{25}+p_{36}-p_{526}-p_{263} - p_{25,36} + p_{5263}.$ Call an index $i$ where $2\leq i\leq n-1$ invalid if $|a_i-a_{i+1}| > 2.$ Let $g(n)$ be the number of these permutations with $a_n = n$. Then $g(1)=1, g(2)=1, g(3)=1, g(4)=2.$ Clearly in any permutation counted by $g(n), a_{n-1} \ge n-2.$ In general, $a_{n-i}\geq n-2i$ for $1\leq i < n$, though clearly this bound is very rough.

Let $h(n)=f(n)-g(n)$. There should be a recurrence formula for $g(n)$ and $h(n)$, but I'm not sure how to find it.

Clarification: the question from the original source (provided in a comment) used the bounds $2\leq i\leq n-1$, so I assume that's what's intended.

user33096
  • 2,081
  • 3
  • 12
  • 3
    Clarification requested: Are you sure that the constraint is $$\cdots ~\text{for}~ \color{red}{2}\leq i\leq n-1$$ rather than $$\cdots ~\text{for}~ \color{red}{1}\leq i\leq n-1 ~?$$ – user2661923 Nov 19 '22 at 04:27
  • This is close enough to https://oeis.org/A003274 that you might be able to make use of the information at that link. – Gerry Myerson Nov 19 '22 at 04:32
  • @user2661923, the numbers OP gives are consistent with the constraint as OP gives it, e.g., for $n=4$, OP is OK with the permutation 1432. So, the $a_1=1$ is really irrelevant; we're counting permutation of $2,3,\dots,n$ with $|a_i-a_{i+1}|\le2$. And that makes it exactly the sequence in the link I gave. But clarification from OP would be good. – Gerry Myerson Nov 19 '22 at 04:48
  • 1
    What is the source of this problem, please? – Gerry Myerson Nov 19 '22 at 05:02
  • Please, 33096, engage with the comments on your question. – Gerry Myerson Nov 20 '22 at 11:09
  • I’m voting to close this question because OP is impervious to comments. – Gerry Myerson Nov 22 '22 at 03:24
  • @GerryMyerson sorry for not responding in a long time. The source of the problem is question 12 from a putnam training problem set. – user33096 Nov 22 '22 at 03:40
  • @user2661923 I've added a clarification. – user33096 Nov 22 '22 at 03:41
  • Good. Now: have you looked at the oeis link I gave? Have you understood it? Does it help answer your question? – Gerry Myerson Nov 22 '22 at 10:21
  • Still ignoring comments. – Gerry Myerson Nov 23 '22 at 23:43
  • @GerryMyerson unfortunately I don't understand the content of any of the links on that site. Honestly if this problem is so hard I can't even understand a single answer to it, I honestly don't care anymore. It's much more productive to actually solve some questions, even if they are significantly easier, than to struggle to even understand insanely hard questions. If you do feel like posting an answer to this question, I won't delete it even if I don't understand your answer, so don't concern yourself over that. – user33096 Nov 24 '22 at 02:27
  • As it's from Putnam training, I expect it to be hard, but not insanely hard. I'll give it another look, when I get a chance. – Gerry Myerson Nov 24 '22 at 05:25

1 Answers1

1

I'm going to answer the question,

For any positive integer $n$, let $f(n)$ be the number of permutations $a_1,\cdots, a_n$ of $1,\cdots, n$ so that $a_1=1$ and $|a_i-a_{i+1}|\leq 2$ for $1\leq i\leq n-1$. Find $f(2022)\pmod 3$,

which differs from the question as posted in having $1\leq i\leq n-1$ instead of $2\leq i\leq n-1$. The question makes more sense to me, starting at $i=1$ than at $i=2$ – see the comments. Also, the question with $i=1$ is easier, and also, you probably have to understand the $i=1$ question to be able to solve the $i=2$ question. So, here goes.

Note that $a_2$ must be two or three.

Case 1: $a_2=2$. Then $(a_2-1,a_3-1,\dots,a_n-1)$ is a permutation of $1,2,\dots,n-1$ satisfying the conditions, so there are $f(n-1)$ of these.

Case 2: $a_2=3$ and $a_3=2$. Then we must have $a_4=4$, and $(a_4-3,a_5-3,\dots,a_n-3)$ is a permutation of $1,2,\dots,n-3$ satisfying the conditions, so there are $f(n-3)$ of them.

Case 3: $a_2=3$, and $a_3\ne2$. Then $2$ is not next to $1$, and not next to $3$, so it must only be next to $4$, so we must have $a_n=2$, and $a_{n-1}=4$. Then we must have $a_3=5$, and then $a_{n-2}=6$, and so on; the permutation must be $(1,3,5,7,\dots,8,6,4,2)$.

So we have $f(n)=f(n-1)+f(n-3)+1$, with $f(1)=1$, $f(2)=1$, $f(3)=2$.

So we have $f(n)\equiv f(n-1)+f(n-3)+1\bmod3$, with $f(1)=1$, $f(2)=1$, $f(3)=2$. Using this recurrence to compute the first few terms, we get $$ 1,1,2,1,0,0,2,0,1,1,2 $$ and as soon as we see $1,1,2$ repeated, we know the sequence will be periodic, repeating $1,1,2,1,0,0,2,0$ forever (since each term is determined by the previous three terms). This has period eight, and $2022\equiv6\bmod3$, so $$ f(2022)\equiv f(6)\equiv0\bmod3 $$

Gerry Myerson
  • 185,413
  • Thanks for the answer. I actually understand it quite well. I don't know why the original post used $2\leq i\leq n-1$ instead of $1\leq i\leq n-1$; it was probably a typo. Also, this answer seems a bit easy based on some of the answers to the problem 12s of similar problem sets I've seen. – user33096 Dec 04 '22 at 01:33
  • This discussion actually had a lot of ambiguities, including that $2\leq i\leq n-1$ discrepancy. I apologize for that. Did you provide some links similar to the answer you just posted? It seems a lot of the links on the oeis page cover much more complicated proofs, which is why I was confused. – user33096 Dec 04 '22 at 01:34
  • The problem with $2\le i\le n-1$ is harder, it leads to more cases than the problem with $1\le i\le n-1$, so to more complicated proofs. – Gerry Myerson Dec 04 '22 at 03:02
  • Thanks. Could you look at this Dyck path/modular arithmetic problem if you have time? – user33096 Dec 18 '22 at 00:34
  • Sorry, I don't think I'll have anything useful to say about that one. – Gerry Myerson Dec 18 '22 at 04:19