Math exercises
Lately I’ve been enjoying reading about math puzzles on social media. Once in a while they creep into my feeds as brainteasers, or even worse, in nicely produced short reels paired with satisfying audio stimuli.
I realised, other than giving my brain a nice flex and occasionally getting quick dopamine hits, attempting to compulsively go through these brain teasers serve me no good; there’s simply too many interesting problems, and I should spend my precious attention on things that do matter.
Anyway here’s one math problem I recently read about.
Melancholy of Haruhi Suzumi has 14 episodes in its first season. The episodes were not aired in a linear, chronological order. Fans thus realised the season can be rewatched in any sequence, and supposedly you’ll get a different experience based on the order you followed. I haven’t watched this series before but I guess it’d be similar to The Godfather, Back to the Future, or Infernal Affairs trilogies.
One day, someone posted the following question on 4chan: given n = 14 episodes in a season, what is the minimum number of episodes to watch consecutively, such that after finishing the anime marathon, one would have watched all the possible episode arrangements?
With n=14, the number of permutations for season 1 would be 14!. If I just the full season in all 14! orders, I would definitely have covered all the permutations. This sets an initial upper limit to 14 (episodes) x 14! (permutations).
That’s not the minimum number, though.
And so it goes that an anonymous user (every time!) replied with a lower bound, which was subsequently confirmed by mathematicians. Years later, even smaller lower bounds have been found. What made me curious was the fact that the answer is presented in a range but not an absolute number. I know for a fact for shorter seasons (e.g. n=3), we definitely have an absolute min number.
When n=3, there are 3!=6 permutations:
- 123
- 132
- 213
- 231
- 312
- 321
The minimum number of episodes to watch is 9, because you can watch it in the order of “123121321". One can draw up the shortest possible sequence by hand.
Inspecting the logic closely, you needed 3 episodes to complete the 1st permutation “123”. This took the most number of episodes (unavoidably).
After this, it took 1 more episode (ep1) to complete the 2nd permutation “231”, and 1 more (ep2) to complete “312”. So 2 more episodes for 2 more permutations — efficient progress.
After “312”, one cannot repeat the efficient operation by adding another ep3 behind, because we have already completed “123”. Adding ep2 also doesn’t make sense, because a double-2 means the 2 within “312” is not utilised towards the next sequence efficiently. The most efficient step is therefore keeping that 2, and adding ep1, ep3 to reset and complete “213”. This step took us 2 extra episodes, for just 1 new permutation.
Finally, we can run 2 efficient operations (adding ep2, ep1) to achieve “132” and “321”. This completes all 6 permutations and took us watching 9 episodes in total. When n=3, permutations=3!, answer=9.
For completeness, when n=2, permutations=2!, answer=3 (“121”).
When n=4, permutations=4!=24.
The shortest sequence is again easily spelled out to be “1234 123 14 231 24 312 134 213 24 132 14 321”
33 episodes.
Studying the logic more closely. For n=4:
The number of episodes it took was
n (initial / unavoidable)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
3 (a longer reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
And the number of permutations attained come in the pattern of 1,3,1,3,1,3,1,3,1,3,1,3 which sums up to 24 (24 possible permutations). The pattern is actually 1, n-1 repeated 6 times. How many times this repeats is computed as n!/(n-1+1) = (n-1)!. This means there are (n-1)! odd rows and (n-1)! even rows in the above table.
Notice all even rows are just n-1=3 in this case. It is said to be (most efficient) because adding 3 episodes yield 3 additional permutations in this operation.
The odd rows form the pattern 4,2,2,3,2,2 for n=4.
To compute the answer 33, even rows add up to (n-1) x (n-1)! times = 3 x 6 = 18. Odd rows sum up to n, 2, 2, n-1, 2, 2, where 2 refer to the 2-step resetting operation, and n-1=3 is the longer resetting operation. 18+15=33.
When n=5, the shortest sequence of episodes:
“12345 1234 15 2341 25 3412 35 4123 145 2314 25 3142…”
Get Eugene Lee’s stories in your inbox
Join Medium for free to get updates from this writer.
The number of episodes it took was
n (initial)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
3 (a longer reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
2 (reset)
n-1 (most efficient)
… and so on
Writing down n and their corresponding number of episodes (but omitting the even rows, given we’ve proven the sum equals (n-1) x (n-1)!)
Within the odd rows, the sum of all 2s (2-step reset) can be written as (n-2) x (n-2)! x 2
Now it’s really the first number of each row within the odd rows that we care about.
Writing them down separately, a pattern starts to form again.
For each group here, after taking advantage of (n-2) of 2-steps (spelled out above for n≤6 but omitted for n=7), it needs to take a longer 3 steps to do a reset, again followed by more 2-steps. This 3-step operation only can be repeated for (n-3) times, after which an even longer reset of 4 steps is required. This 4-step can be done (n-4) times, after which an even longer reset of 5 steps is required. The longest resetting step of 6 (for n=7) only needs to be performed once, in the middle of the groups (i.e. at group 13 when there are 24 groups). The rest just repeats symmetrically.
So for n=7, in the odd rows only:
- the number of 2-step resets are (n-2) groups x (n-2)! times = 600
- the number of 3-step resets are (n-3)! groups x (n-3) times = 96
- the number of 4-step (n-3) = (n-3)! groups / (n-3) sub-group size x (n-4) times = 18
- 5-step (n-2) = (n-3)! groups / (n-3) sub-group size -2 (2 refers to the 1x n step (beginning) and 1x n-1 step (middle) = 4
- 6-step (n-1) = 1 (performed once in the middle section)
- n-step = 1 (performed at the very beginning)
Answer for n=7:
Odd rows: 600x2 + 96x3 + 18x4 + 4x5 + 1x6 + 1x7 = 1593 +
Even rows: (n-1) x (n-1)! = 6 x 6! = 4320
= 5913… which is my answer based on logically observing and deducing the number patterns
Conducting a simple cross-check from online sources, a lowest upper bound was established just 2 months ago at 5905.
This means there must be some more efficient tactics to save steps.
I checked that for n=6, the latest upper bound (shortest sequence found) is 872 (but also not yet proven to be the lowest exact number). My calculations yield an answer of 873. Given the difference is just 1, maybe I can spend more time studying the known solution(s) to 872 and understand where the extra savings could come from. I can check at which digit the 872-number sequence starts to deviate from my “most obvious answer” of “123456 12345 16 23451 26 34512 36…”
Maybe not.
Afterword:
- It was fun to explore the concept of superpermutation as a mental workout. I’m lucky I emerged mentally intact. This is a case in point for why attempting to solve endless mathematical riddles is just a waste of time and often futile.
2. I shared this finding with a friend who was a math major. He pointed out that math problems might have been solved elegantly through brute imagination or intuition in the early days (I thought about Pythagoras), but modern strategies often involves abstract techniques and perhaps using imaginary numbers as the means. This reminds me of a recent learning that it’s often more difficult than one can imagine to attack certain fields without deep domain knowledge or extensive time invested in the research of all adjacent areas.
3. Quite a timely exercise to reflect on the recent controversy caused by AI labs hacking mathematical problems. Mathematicians criticised AI’s lack of genuine understanding of those proofs or solutions generated, without which, they argue, there will be no practical value of those solutions. Perhaps my approach in this particular exercise — trying to attack the problem through intuition and logic and pattern recognition — shares the same shortcomings.
4. All em-dashes were manually added.





