Finit le jour 8 et le début du 9

This commit is contained in:
2021-12-09 17:31:46 +01:00
parent f1899b0640
commit c290b5fee6
3 changed files with 145 additions and 0 deletions

15
day_8/part_1.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
$output = array_map(static function ($line) {
return explode('|', $line)[1];
}, explode("\n", file_get_contents('./input.txt')));
echo array_reduce($output, static function($carry, $item) {
$count = 0;
$items = explode(' ', $item);
foreach ($items as $item) {
$count += in_array(strlen($item), [2, 4, 3, 7]) ? 1 : 0;
}
$carry += $count;
return $carry;
});