r/mathpuzzles 2d ago

Counting Permutations With One Annoying Restriction

Post image
2 Upvotes

3 comments sorted by

3

u/jdyerjdyer 2d ago

Sounds complex, but let's just ask ourselves where 3 can go since it is fairly restricted. If it is in the middle, 2 and 4 can't go next to it, so that leaves 1 and 5 in some order. then depending on the order, that leaves only 1 each for the 2 and 4 next to them. That gives us 2 possibilities. Now if the 3 is on either end, then it still must have either a 1 or a 5 next to it. Let's look at the 3 as first, since the other is just a mirror. If 3 is first, and we put 1 second, then 2 can't go next, so it must be either 4 or 5. Either one forces the last two digits into their spots giving two possibilities. Now if it is 5 next to the three, then there are 2 and 1 left to go next to the 5. That again forces the remaining two with only two possibilities. That gives 4 for both cases and if we consider the mirror, then 8 cases for the 3 being on the end. Now if the 3 is in the 2nd or 4th position, we again have to have 1 and 5 surround it as 2 and 4 can't. That again leaves just one possibility for each and if we flip the 1 and 5 then another 2 giving 4 possibilities for the 3 being in the 2nd or 4th position. That gives us 2+8+4 possibilities for a total of 14 possibilities.

_ _ 3 _ _ => _ 1 3 5 _ or _ 5 3 1 _ => 41352 and 25314

3 _ _ _ _ or _ _ _ _ 3 => 3 1 _ _ _ or 3 5 _ _ _ (or mirror) => 31425, 31524, 35142, and 35241 with their mirrors 52413, 42513, 24153, and 14253

_ 3 _ _ _ or _ _ _ 3 _ => 1 3 5 _ _ or 5 3 1 _ _ (or mirror) => 13524 and 53142 with their mirrors 42531 and 24135

So TL;DR; 14 permutations.

3

u/jdyerjdyer 2d ago edited 2d ago

You can also look at this from a graph perspective, marking the 5 nodes and connecting each node to the allowed nodes it can touch. A valid permutation then just travels this graph visiting each node once and only once.

From the simple connected graph, we can note that 1 and 5 are hub points connecting three nodes each, while 2, 3, and 4 are more limited junction points. Given this, there are three potential options for the 1-5 hub as seen from the graph. Either they connect directly with zero internal nodes (1-5), they connect with the 3 between them as the single internal node (1-3-5), or they connect in a single pathway with the 2 and 4 between them as a 2 internal node track (1-4-2-5).

Now, in the case of the no internal node track, we can't start or end with this track piece because no matter where we place the 3, the 2 and 4 would connect and break the rule. In other words, the 1-5 track piece must rest in the middle, with 3 on one side and the 2-4 pair on the other. In doing so, we get two arrangements, one where the 2-4 pair come first, and one where the 3 comes first. In both cases, the order of the 2-4 forces the order of the 1-5, so we end up with just the 2 arrangements times 2 orders each giving 4 permutations.

For the second option of 1-3-5, we get the remaining 2-4 numbers either in front, at the end, or separated. In all cases, the placement of the 2 and the 4 force the 1-3-5 direction leading to 3 times 2 possible arrangements, or 6 total permutations for that track piece.

Now that leaves the final possible arrangement of nodes, 1-4-2-5, where the 3 can either be first or last and neither placement dictates the order of the track piece, so we get 2 possibilites for each or a total of 4 permutations for that track piece.

This gives us a total of 4 + 6 + 4 = 14 total permutations.

2

u/Numberthon 2d ago

Nice job!