Files
advent_of_code_2021/06/part2.php
2021-12-06 18:05:48 +01:00

19 lines
435 B
PHP

<?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 <= 256; $i++) {
$newBorns = $fishes[0];
for ($j = 1; $j <= 8; $j++) {
$fishes[$j - 1] = $fishes[$j];
}
$fishes[6] += $newBorns;
$fishes[8] = $newBorns;
}
echo array_sum($fishes); //1746710169834