]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/07.pl
Year 2016, days 1-10: so far pretty interesting
[aoc.git] / 2016 / 07.pl
diff --git a/2016/07.pl b/2016/07.pl
new file mode 100755 (executable)
index 0000000..fd8ba32
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $sum;
+while (<>) {
+       chomp;
+       my ($code, $id, $csum) = /\A([a-z-]+)-(\d+)\[([a-z]{5})\]/;
+       my %hist;
+       $hist{$&}++ while ($code =~ /[a-z]/g);
+       my $c1;
+       for my $l (sort { $hist{$b} <=> $hist{$a} || $a cmp $b } keys %hist) {
+               $c1 .= $l;
+               last if length $c1 >= length $csum;
+       }
+       $sum += $id if $csum eq $c1;
+}
+say $sum;