19 lines
435 B
PHP
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
|