6th day 1st part

This commit is contained in:
kplaczek
2021-12-06 18:05:33 +01:00
parent 5755201a62
commit c184b6b59c
2 changed files with 20 additions and 0 deletions

19
06/part1.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$input = explode(',', $input[0]);
$fishes = array_fill(0, 9, 0);
foreach ($input as $fish) {
$fishes[$fish]++;
}
for ($i = 1; $i <= 80; $i++) {
$newLanternFish = $fishes[0];
for ($j = 1; $j <= 8; $j++) {
$fishes[$j-1] = $fishes[$j];
}
$fishes[6] += $newLanternFish;
$fishes[8] = $newLanternFish;
}
echo array_sum($fishes); //390011