Arrangement without any monotone section 
Here's the question:
"In how many ways can the sequence 45678 be arranged such that there aren't any three consecutive terms increasing or decreasing"

The first thing I thought of is to do complementary counting and then make cases for each number of consecutive terms that there could be (3, 4, 5).
However there's a lot of overlap between the three cases and I'm not sure how to deal with that in an efficient way. If someone could solve it and then tell me how they did it that would be great.
 A: We have 5 digits, so after filling the first digit, we have to decide 4 times if we want to increase ($i$) the next digit or decrease($d$).
We have to take $i$ and $d$ alternatively, because if two $i$ or two $d$ are together, then there will be 3 consecutive terms increasing or decreasing.
For that, there can only be 2 cases ($idid$) and ($didi$), in these two cases, we have only interchanged $i$ and $d$, so they will have the same number of cases.
For $idid$:

*

*First digit 7, $78564$, $78465$.

*First digit 6, $68475$, $68574$, $67485$, $67584$.

*First digit 5, $58476$, $58674$, $57486$, $57684$, $56487$

*First digit 4, $46587$, $47586$, $47685$, $48576$, $48675$
Number of ways: 16
$$\boxed{\text{FINAL RESULT}: \underbrace{16}_\text{idid} + \underbrace{16}_\text{didi} = 32}$$
A: We notice if we rotate the digits of a number we get five different numbers. There is always $2$ good numbers (no three consecutive inc/dec terms) or $0$ good number among the five numbers. If there is only one inc/dec sequence in the "circular configuration" then there are two good numbers. If there are more than one such sequence then there is no good number.
It's easy to see there are $24$ such "rotational classes."
Among these five numbers of the same class there is always a number where the middle number is $6$. We notice that if the numbers to the left of $6$ and to the right of $6$ are both less than or greater than $6$. Then the number itself is good so it must be the "$2$ out of $5$" case. There are $2\times 2\times2=8$ such classes, calculated by grouping $(4,5)$ and $(7,8)$ together, switching each group's number order and switching the groups.
Out of the remaining $16$ classes, we again look at the number where $6$ is in the middle. Notice that we can have a bijection by switching the numbers before and after the middle $6$. If the original class is a "$2$ out of $5$" class then the class after switching is always "$0$ out of $5$", and vice versa. This comes from the fact that if the number is $ab6cd$ then the class is good only when $ad$ and $bc$ has reverse order so switching $b,c$ will turn a good class into bad and a bad class into good.
This means exactly $8$ classes out of the $16$ classes have "$2$ out of $5$" numbers being good.
This means there are totally $16$ good classes and $16\times2=32$ good numbers.
A: My simple Python script enumerates them as
(4, 6, 5, 8, 7)
(4, 7, 5, 8, 6)
(4, 7, 6, 8, 5)
(4, 8, 5, 7, 6)
(4, 8, 6, 7, 5)
(5, 4, 7, 6, 8)
(5, 4, 8, 6, 7)
(5, 6, 4, 8, 7)
(5, 7, 4, 8, 6)
(5, 7, 6, 8, 4)
(5, 8, 4, 7, 6)
(5, 8, 6, 7, 4)
(6, 4, 7, 5, 8)
(6, 4, 8, 5, 7)
(6, 5, 7, 4, 8)
(6, 5, 8, 4, 7)
(6, 7, 4, 8, 5)
(6, 7, 5, 8, 4)
(6, 8, 4, 7, 5)
(6, 8, 5, 7, 4)
(7, 4, 6, 5, 8)
(7, 4, 8, 5, 6)
(7, 5, 6, 4, 8)
(7, 5, 8, 4, 6)
(7, 6, 8, 4, 5)
(7, 8, 4, 6, 5)
(7, 8, 5, 6, 4)
(8, 4, 6, 5, 7)
(8, 4, 7, 5, 6)
(8, 5, 6, 4, 7)
(8, 5, 7, 4, 6)
(8, 6, 7, 4, 5)
so there are $32$
