Finit le jour 7 partie 1

This commit is contained in:
Clement Desmidt
2026-01-12 15:34:23 +01:00
parent 4b3f8412c9
commit 315c7632f8

26
day_7/part_1.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
include '../functions.php';
$rows = explode("\n", file_get_contents("input.txt"));
$count_split = 0;
$indexes = [];
$indexes[] = array_search('S', str_split(array_shift($rows)));
foreach ($rows as $row) {
foreach ($indexes as $index) {
if ($row[$index] === '^') {
$indexes[] = $index-1;
$indexes[] = $index+1;
unset($indexes[array_search($index, $indexes)]);
$indexes = array_unique($indexes);
$count_split++;
}
}
}
echo $count_split;