The Shredder Conundrum

Problem #312

Tags: unlabeled

Who solved this?

No translations... yet

This is the new chapter in adventures of Holmes and Watson, brought to us by Vladimir V. Zelevinsky - for which we are much grateful - if you find it amusing, make sure not to miss the preceeding ones!

Holmes raced into our sitting room at 221B, Baker Street, in triumphant spirits.

"Victory, Watson!" he bellowed, waving what looked like a handful of paper strips. "It took months of planning, but I finally got my hands on the contents of Moriarty's safe!"

"Sounds like a major breakthrough!" I said.

"This is of tremendous importance!" exclaimed Holmes. "I showed up at his lodgings with a detachment of the Scotland Yard finest and a search warrant. Since I knew that this devious mastermind would attempt to destroy any incriminating evidence, I had Lestrade, wearing a diving suit, floating in the sewers, just in case Moriarty tried to flush his papers down the toilet! Likewise, I had Gregson, disguised as Santa Claus, hiding in the chimney with a bucket of water, in case Moriarty decided to burn the evidence in the fireplace!"

Then the jubilant expression on Holmes's face faded slightly.

"What I failed to consider," he added, somewhat sourly, "is that this criminal genius would own a newfangled invention called a shredder."

"A what, Holmes?" I asked.

"A shredder," he said. "It is a fiendish device, undoubtedly invented by career criminals to help them dispose of evidence. It takes a sheet of paper and runs it through a set of parallel blades, cutting it into a set of vertical strips. After the document is thus shredded, the reconstruction of it becomes a difficult, if not to say an impossible, task. Now, naturally, Moriarty is claiming that this document was nothing but his favorite recipe for chocolate cake, but he's obviously lying. As for me, I am left holding a handful of confetti."

"How many strips are there?" I asked as Holmes spread them on the desk.

"It appears that Moriarty's shredder has nineteen blades, meaning we have 20 strips. It also looks like each strip is quite narrow, only two characters wide."

"Twenty strips!" I exclaimed. "But this means we'll need to try twenty factorial combinations, which is..."

"2432902008176640000," said Holmes without skipping a beat. "We'd better start working on this right away, Watson."


Can you please help Holmes and Watson recover the contents of the shredded document?

The puzzle input starts with a single number N: the number of lines in the document. The following N lines contain 20 vertical strips (separated by the vertical pipe character |) in some random order.

Your task is to unscramble the contents. For the ease of checking, please provide the answer as the entire document on a single line, replacing line and paragraph breaks with spaces. Simply pasting the unscrambled text (it will be on the order of a thousand characters long) in the "Your answer" box below should do the trick (the checker is reasonably accommodating with regards to whitespace).

Here is a little example with fewer strips (in this case, 13).

input:
5
|ar|nk|y | i|gu|de|ba|dl|ba|Th|s |d |e |
| t|n |s |th|of|hr|ee|ur|ho|be|e |ee|tw|
|  |ve|t.| a|  |  |fi|gh|ni|an|t |  |d |
|e |s | t|th|im|to| i|st|be|Th|e |  |is|
|pl|e |er|ou|y |an|ut|bb|ro|ex|r |s.|ec|

unscrambled document:
The bank is badly guarded
between the hours of three
and five at night.
This is the best time to
execute our robbery plans.

answer:
The bank is badly guarded between the hours of three and five at night. This is the best time to execute our robbery plans.
You need to login to get test data and submit solution.