--- Day 5: The Rune Reconstruction ---
You're still calculating optimal carrot-to-tunnel ratios in your head when Patch appears at your workstation the next morning, holding two steaming mugs of cocoa.
"Don't get comfortable," he says, sliding one mug across your desk. "Vixen's tunnels are operational, but now we have a different problem. A much older problem". He pulls up a grainy security feed on your monitor. It shows a massive vault door deep in Sub-Level 7, covered in glowing symbols and what appears to be broken stone tablets scattered across the floor.
"The Archives," Patch explains. "Turns out the this hotel has been around a lot longer than we thought. And someone - probably an overeager elf during last year's 'Modernisation Initiative' - tried to access the Ancient Logistics Records without knowing the proper authentication protocols."
"They broke the door?" you ask.
"They broke the lock," Patch corrects. "The door has a runic command system. Think of it like... a very old, very particular password. The authentication tablets are now in pieces on the floor, and the vault won't open without a properly formatted command sequence."
He hands you a tablet displaying dozens of fragment scans. Each piece contains strange characters: (, ), [, ], {, }, <, >, mixed with ancient script.
"The fragments need to be reassembled into a valid command sequence," Patch continues. "All fragments must be used exactly once, but the order matters. And according to the dusty manual I found, the resulting string has to follow the Ancient Grammar Rules."
Patch pulls up a brittle page of documentation. "Why do we need these archives?" you ask.
Patch's expression turns serious. "Because according to Vixen's thermal scans, there are more tunnel systems down there. Older ones. And if we don't understand how they were originally designed, our new tunnels might intersect with them in... problematic ways." He gestures to the fragments. "Can you figure out the correct sequence to unlock the vault before the engineering team accidentally drills into a thousand-year-old reindeer expressway?"
To open the door, you must reassemble the fragments into a valid command sequence.
The fragments contain characters from an ancient syntax: (, ), [, ], {, }, <, >, and other text characters. A valid command is a single string formed by concatenating all of the supplied fragments exactly once.
However, the order matters, and the resulting string must adhere to the ancient grammar rules:
(), [], {}, <>), and they must be properly nested.
([]), {[()]}, ()[]{}([), )(, ([)]{ and } represented a "Faraday Cage" that blocked radio signals.
(...) cannot exist anywhere inside a Faraday Cage {...}.{, you cannot open a (.< and > represent flow channels. Flow must be continuous.
> must not be immediately followed by a "solid" opener: (, [, or {.< must not be immediately followed by a "solid" closer: ), ], or }....>{......><... or ...>>... or ...>]...All other non-bracket letters/numbers should be ignored for the purposes of reassembly.
The input file contains a list of fragment cases. Each case is separated by a newline, and each fragment within each case is separated by a space.
Arrange all of the fragments to find the total possible number of unique permutations of fragments that result in a valid message according to the rules above.
Output, for each case, the number of unique valid messages that can be formed. Separate your answers with a semicolon.
Example input: )] [ (< a>
Output: 1. The only valid permutation is [(<a>)]