✨ Finit le jour 7 partie 1
This commit is contained in:
26
day_7/part_1.php
Normal file
26
day_7/part_1.php
Normal 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;
|
||||
Reference in New Issue
Block a user