34 lines
767 B
PHP
34 lines
767 B
PHP
<?php
|
|
|
|
$lines = explode("\n", file_get_contents('./input.txt'));
|
|
|
|
$scores = [
|
|
')' => 3,
|
|
']' => 57,
|
|
'}' => 1197,
|
|
'>' => 25137,
|
|
];
|
|
|
|
$corrupted = [];
|
|
|
|
foreach ($lines as $line) {
|
|
$chunks = [];
|
|
foreach (str_split($line) as $chunk) {
|
|
switch ($chunk) {
|
|
case '(': $chunks[] = ')';break;
|
|
case '[': $chunks[] = ']';break;
|
|
case '{': $chunks[] = '}';break;
|
|
case '<': $chunks[] = '>';break;
|
|
default:
|
|
$last_chunk = array_pop($chunks);
|
|
if ($last_chunk !== $chunk) {
|
|
$corrupted[] = $chunk;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
echo array_sum(array_map(static function ($score) use ($scores) {
|
|
return $scores[$score];
|
|
}, $corrupted));
|