✨ Finit le jour 10
This commit is contained in:
33
day_10/part_1.php
Normal file
33
day_10/part_1.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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));
|
Reference in New Issue
Block a user