From 2145fe3dc17910991e5acbe1bdc8d1d8ec310e78 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 6 Dec 2021 10:42:57 -0500 Subject: Solve day 6 part 2 --- 2021/day06.pl | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to '2021') diff --git a/2021/day06.pl b/2021/day06.pl index b296a4c..3fc7ac2 100644 --- a/2021/day06.pl +++ b/2021/day06.pl @@ -1,16 +1,32 @@ use strict; use warnings; -my @fish = split(/,/, <>); +my @init = split(/,/, <>); +my @fish = @init; for (1..80) { my @spawns; - for my $f (@fish) { - if ($f) { - $f--; + for (@fish) { + if ($_) { + $_--; } else { - $f = 6; + $_ = 6; push @spawns, 8; } } push @fish, @spawns; } print scalar(@fish), "\n"; +my %counts; +for (@init) { + $counts{$_}++; +} +for (1..256) { + my $zeros = $counts{0} // 0; + for (0..7) { + $counts{$_} = $counts{$_+1}; + } + $counts{8} = $zeros; + $counts{6} += $zeros; +} +my $sum = 0; +$sum += $_ for values %counts; +print "$sum\n"; -- cgit 1.4.1 ary refs log tree commit diff
path: root/bin/modem.c (unfollow)
Commit message (Collapse)Author
2022-02-14Remove cgitJune McEnroe
My fork of cgit is now <https://git.causal.agency/cgit-pink/>.
2022-02-14Narrow filterJune McEnroe
2022-02-10Correct diminishing shine, I thinkJune McEnroe