Part 2: Filter out corrupt, then "complete" them by maintaining a stack of characters (add if left, remove if matching right), then flip the characters in the stack, ie '(' -> ')'.
Map chars to individual values, then score, sort, find middle entry
ALT autocompleteScore :: [String] -> Int
autocompleteScore ls = scores !! (length scores `div` 2)
where
autocompletes = map (completeLine []) (getIncompleteLines ls)
scores = sort $ map (foldl (\a x -> (a * 5) x) 0 . map score') autocompletes
getIncompleteLines :: [String] -> [String]
getIncompleteLines lines = [x | (i, x) <- zip [0 ..] lines, lines' !! i == ' ']
where
lines' = map (firstInvalidChar...