I've recently encountered the following puzzle that seems a bit too "mathy" for Puzzling Stack Exchange so I decided to ask here. This is not a homework.
The numbers from $1$ to $15$ must be put in a sequence with the two numbers fixed:
- The $4$th number is $15$.
- The $8$th number is $8$.
($1$-based counting)
How many such sequences exist where the sum of any $3$ neighboring numbers is divisible by $3$?
Let $a_i$ be the $i$-th number of the sequence then $a_i\equiv a_{i+3}\equiv -a_{i+1}-a_{i+2}\mod 3$ since the sum of three consecutive numbers is $0$ modulo $3$.
By the given restrictions we get $$a_i\equiv\begin{cases}0&\text{if }3\mid (i-1)\\1&\text{if }3\mid i\\2&\text{if }3\mid(i-2)\end{cases} \mod 3.$$
Every way of putting numbers that satisfy the above, is a solution. So the total number of possibilities is $4!\cdot 5!\cdot 4!$ (number of permutations for elements with index $\equiv1\mod 3$ and $i\neq 4$ times number of permutations for elements with index $\equiv0\mod3$ times number of permutations for elements with index $\equiv2\mod3$ and $i\neq8$).