26 lines
445 B
PHP
26 lines
445 B
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
$input = file_get_contents("input");
|
|
$input = explode(",", trim($input));
|
|
|
|
$fish = array_count_values($input);
|
|
for($i=0; $i<=10; $i++)
|
|
if(!array_key_exists($i, $fish)) $fish[$i] = 0;
|
|
|
|
$days = 256;
|
|
|
|
for($day=0; $day<$days; $day++) {
|
|
$fish[7] += $fish[0];
|
|
$fish[9] += $fish[0];
|
|
|
|
for($i=0; $i<10; $i++) {
|
|
$fish[$i] = $fish[$i+1];
|
|
}
|
|
}
|
|
|
|
echo "Total number of fish after $days days: " . array_sum($fish) . "\n";
|
|
|
|
|
|
?>
|