20 lines
444 B
PHP
20 lines
444 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 <= 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
|