part2 (2577B)
1--- Part Two --- 2 3Now, discard the corrupted lines. The remaining lines are [1m[37mincomplete[0m. 4 5Incomplete lines don't have any incorrect characters - instead, they're missing some closing 6characters at the end of the line. To repair the navigation subsystem, you just need to figure out 7[1m[37mthe sequence of closing characters[0m that complete all open chunks in the line. 8 9You can only use closing characters (), ], }, or >), and you must add them in the correct order so 10that only legal pairs are formed and all chunks end up closed. 11 12In the example above, there are five incomplete lines: 13 14 15 - [({(<(())[]>[[{[]{<()<>> - Complete by adding }}]])})]. 16 17 - [(()[<>])]({[<{<<[]>>( - Complete by adding )}>]}). 18 19 - (((({<>}<{<{<>}{[]{[]{} - Complete by adding }}>}>)))). 20 21 - {<[[]]>}<{[{[{[]{()[[[] - Complete by adding ]]}}]}]}>. 22 23 - <{([{{}}[<[[[<>{}]]]>[]] - Complete by adding ])}>. 24 25 26Did you know that autocomplete tools [1m[37malso[0m have contests? It's true! The score is determined by 27considering the completion string character-by-character. Start with a total score of 0. Then, for 28each character, multiply the total score by 5 and then increase the total score by the point value 29given for the character in the following table: 30 31 32 - ): 1 point. 33 34 - ]: 2 points. 35 36 - }: 3 points. 37 38 - >: 4 points. 39 40 41So, the last completion string above - ])}> - would be scored as follows: 42 43 44 - Start with a total score of 0. 45 46 - Multiply the total score by 5 to get 0, then add the value of ] (2) to get a new total score of 472. 48 49 - Multiply the total score by 5 to get 10, then add the value of ) (1) to get a new total score of 5011. 51 52 - Multiply the total score by 5 to get 55, then add the value of } (3) to get a new total score of 5358. 54 55 - Multiply the total score by 5 to get 290, then add the value of > (4) to get a new total score of 56294. 57 58 59The five lines' completion strings have total scores as follows: 60 61 62 - }}]])})] - 288957 total points. 63 64 - )}>]}) - 5566 total points. 65 66 - }}>}>)))) - 1480781 total points. 67 68 - ]]}}]}]}> - 995444 total points. 69 70 - ])}> - 294 total points. 71 72 73Autocomplete tools are an odd bunch: the winner is found by [1m[37msorting[0m all of the scores and then 74taking the [1m[37mmiddle[0m score. (There will always be an odd number of scores to consider.) In this 75example, the middle score is [1m[37m288957[0m because there are the same number of scores smaller and larger 76than it. 77 78Find the completion string for each incomplete line, score the completion strings, and sort the 79scores. [1m[37mWhat is the middle score?[0m 80 81