<?php $timers = array_map('intval', explode(',', file_get_contents('./input.txt'))); echo sprintf('Initial state: %s', implode(',', $timers)); $timers = array_count_values($timers); for ($i = 0; $i < 256; $i++) { $tmp = array_fill(0, 9, 0); foreach ($timers as $number => $count) { if($number > 0) { $tmp[$number-1] += $count; } else { $tmp[6] += $count; $tmp[8] += $count; } } $timers = $tmp; echo sprintf('After %u day(s): %s with %u zero%s', $i + 1, array_sum($timers), (array_key_exists(0, $timers) ? $timers[0] : 0), "\n"); } echo array_sum($timers);