Consider $12$ as if it were a new character then you have to consider the strings having $12$ (the new character) and 3,4,5 (so length 4).
You have $\binom{4}{1}$ ways of placing the $12$ symbol and then
$3!$ for placing the remaining characters.
So in total:$\binom{4}{1}\cdot 3!= 24$
Of cours it is the same for $23$, $34$ or $45$.
Hence $S_1=4\cdot 24 = 96$.
You perform similar calculations for the other combinations...
Edit after progress:
$S_2$ is the possibility to make a string with two forbidden strings, say $12$ and $23$. Therefore, you have 2 two symbols forbidden strings
and the remaining symbol. They can be placed in $3!$ ways.
Finally you have $\binom{4}{2}$ ways of choosing the two symbols forbidden pair. Therefore:
$S_2=3!\cdot\binom{4}{2}=36$
Now $S_3$ concerns the patterns $123$, $234$ and $345$. If you consider the pattern as a single character then you have $3!$ ways to arrange them together with the two remaining symbols. Hence $S_3=3\cdot 3!=18$
$S_4$ is concerned with the patterns $1234$ and $2345$. You have $2$ possibilities for each one. Hence $S_4=4$
$S_5=1$ of course.
So the final result is 45=120-96+36-18+4-1.
This number is wrong. The following Sage program confirms that the right value is 53. But What was wrong in my reasoning?
This is also confirmed by this small Sage program:
Filtered=[]
MyList=Permutations(['1', '2', '3','4','5']).list()
skip=0
for i in MyList:
for j in range(1,5):
if ((i[j-1]=='1' and i[j]=='2') or (i[j-1]=='2' and i[j]=='3') or (i[j-1]=='3' and i[j]=='4') or (i[j-1]=='4' and i[j]=='5')):
skip=1
if(skip==0):
Filtered += [i]
else:
skip=0
len(Filtered)
Here is the list of all possible patterns (obtained with Sage):
[['1', '3', '2', '5', '4'],
['1', '3', '5', '2', '4'],
['1', '3', '5', '4', '2'],
['1', '4', '2', '5', '3'],
['1', '4', '3', '2', '5'],
['1', '4', '3', '5', '2'],
['1', '5', '2', '4', '3'],
['1', '5', '3', '2', '4'],
['1', '5', '4', '3', '2'],
['2', '1', '3', '5', '4'],
['2', '1', '4', '3', '5'],
['2', '1', '5', '4', '3'],
['2', '4', '1', '3', '5'],
['2', '4', '1', '5', '3'],
['2', '4', '3', '1', '5'],
['2', '4', '3', '5', '1'],
['2', '5', '1', '4', '3'],
['2', '5', '3', '1', '4'],
['2', '5', '4', '1', '3'],
['2', '5', '4', '3', '1'],
['3', '1', '4', '2', '5'],
['3', '1', '5', '2', '4'],
['3', '1', '5', '4', '2'],
['3', '2', '1', '5', '4'],
['3', '2', '4', '1', '5'],
['3', '2', '5', '1', '4'],
['3', '2', '5', '4', '1'],
['3', '5', '1', '4', '2'],
['3', '5', '2', '1', '4'],
['3', '5', '2', '4', '1'],
['3', '5', '4', '2', '1'],
['4', '1', '3', '2', '5'],
['4', '1', '3', '5', '2'],
['4', '1', '5', '3', '2'],
['4', '2', '1', '3', '5'],
['4', '2', '1', '5', '3'],
['4', '2', '5', '1', '3'],
['4', '2', '5', '3', '1'],
['4', '3', '1', '5', '2'],
['4', '3', '2', '1', '5'],
['4', '3', '2', '5', '1'],
['4', '3', '5', '2', '1'],
['5', '1', '3', '2', '4'],
['5', '1', '4', '3', '2'],
['5', '2', '1', '4', '3'],
['5', '2', '4', '1', '3'],
['5', '2', '4', '3', '1'],
['5', '3', '1', '4', '2'],
['5', '3', '2', '1', '4'],
['5', '3', '2', '4', '1'],
['5', '4', '1', '3', '2'],
['5', '4', '2', '1', '3'],
['5', '4', '3', '2', '1']]
Ok now this is the end ;-)