]> www.fi.muni.cz Git - aoc2020.git/blobdiff - 17.pl
Day 9 quick & dirty
[aoc2020.git] / 17.pl
diff --git a/17.pl b/17.pl
new file mode 100755 (executable)
index 0000000..c972894
--- /dev/null
+++ b/17.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my @prev;
+my $len = 25;
+
+while (my $num = <>) {
+       chomp $num;
+       if (@prev >= $len) {
+               shift @prev if @prev > $len;
+               for my $i (0 .. $len-2) {
+                       for my $j ($i+1 .. $len-1) {
+                               if ($prev[$i]+$prev[$j] == $num) {
+                                       goto FOUND;
+                               }
+                       }
+               }
+               print "$num is not a sum of ", join(', ', @prev), "\n";
+               exit 0;
+       FOUND:
+       }
+       push @prev, $num;
+}
+