From 10b3cd3730ab7ee610cc3982169c5b9c3cc09694 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Mon, 6 Dec 2021 16:37:21 +0100 Subject: [PATCH] :sparkles: Finit le jour 6 --- day_6/part_1.php | 19 +++++++++++++++++++ day_6/part_2.php | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 day_6/part_1.php create mode 100644 day_6/part_2.php diff --git a/day_6/part_1.php b/day_6/part_1.php new file mode 100644 index 0000000..8c7c95d --- /dev/null +++ b/day_6/part_1.php @@ -0,0 +1,19 @@ + 0) { + $timers[$t]--; + } else { + $timers[$t] = 6; + $timers[] = 8; + } + } + echo sprintf('After %u day(s): %s%s', $i + 1, implode(',',$timers), "\n"); +} + +echo count($timers); \ No newline at end of file diff --git a/day_6/part_2.php b/day_6/part_2.php new file mode 100644 index 0000000..15d821a --- /dev/null +++ b/day_6/part_2.php @@ -0,0 +1,24 @@ + $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); \ No newline at end of file