6th day 2nd part
This commit is contained in:
18
06/part2.php
Normal file
18
06/part2.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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
|
||||
Reference in New Issue
Block a user