summary refs log tree commit diff homepage
path: root/2021/day06.pl
diff options
context:
space:
mode:
Diffstat (limited to '2021/day06.pl')
-rw-r--r--2021/day06.pl26
1 files changed, 21 insertions, 5 deletions
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";
ada1b05bc30&follow=1'>Limit parsed colors to number of mIRC colorsJune McEnroe 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe 2018-08-04Handle /topicJune McEnroe