summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
Diffstat (limited to '2020')
-rw-r--r--2020/day16.pl30
1 files changed, 30 insertions, 0 deletions
diff --git a/2020/day16.pl b/2020/day16.pl
new file mode 100644
index 0000000..8ebe521
--- /dev/null
+++ b/2020/day16.pl
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+my (%rules, @ticket, @nearby);
+while (<>) {
+	chomp;
+	if (/([^:]+): (\d+)-(\d+) or (\d+)-(\d+)/) {
+		$rules{$1} = [$2, $3, $4, $5];
+	} elsif (/your ticket:/) {
+		<>;
+		chomp;
+		@ticket = split ',';
+	} elsif (/^[\d,]+$/) {
+		my @fields = split ',';
+		push @nearby, \@fields;
+	}
+}
+
+my $error = 0;
+foreach my $t (@nearby) {
+	foreach my $f (@$t) {
+		my $valid = 0;
+		foreach my $r (values %rules) {
+			$valid = 1 if $f >= $$r[0] && $f <= $$r[1];
+			$valid = 1 if $f >= $$r[2] && $f <= $$r[3];
+		}
+		$error += $f unless $valid;
+	}
+}
+print "$error\n";
-0400'>2018-09-18Refactor reads in pngo and clear palette between filesJune McEnroe 2018-09-17Add tRNS support to pngoJune McEnroe 2018-09-11Move gfx man pages to gfx/manJune McEnroe 2018-09-11Move bin man pages to bin/manJune McEnroe 2018-09-11Rewrite gfx.7 and render plaintext READMEJune McEnroe 2018-09-11Remove GAMES from BINSJune McEnroe 2018-09-11Rewrite bin.7 and render to plaintext READMEJune McEnroe 2018-09-11Add "blank" lines to man pagesJune McEnroe 2018-09-10Add mdoc syntax fileJune McEnroe 2018-09-08Fix Nm usage in multi-name man pagesJune McEnroe 2018-09-08Put real dates on man pagesJune McEnroe 2018-09-08Replace gfx README with REAMDE.7June McEnroe 2018-09-08Link gfx man pages in ~/.localJune McEnroe