--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my @nums = sort { $a <=> $b } <>;
+chomp @nums;
+
+while (@nums > 1) {
+ print "Nums: ", join(' ', @nums), "\n";
+ my $cmp = $nums[0] + $nums[-1] <=> 2020;
+ if ($cmp < 0) {
+ shift @nums;
+ } elsif ($cmp == 0) {
+ print "$nums[0]*$nums[-1]=", $nums[0]*$nums[-1], "\n";
+ last;
+ } else {
+ pop @nums;
+ }
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my @seats;
+while (<>) {
+ chomp;
+ y/FBRL/0110/;
+ my $seat = eval "0b$_";
+ $seats[$seat] = 1;
+}
+
+for (1 .. $#seats-1) {
+ print $_, "\n" if $seats[$_-1] && $seats[$_+1]
+ && !$seats[$_];
+}
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+local $/ = "\n\n";
+
+my $sum = 0;
+
+while (<>) {
+ s/\n//g;
+ my %q = map { $_ => 1 } split //;
+ $sum += keys %q;
+}
+
+print "$sum\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use Data::Dumper;
+
+local $/ = "\n\n";
+
+my $sum = 0;
+
+while (<>) {
+ my $nper = 0;
+ my %q;
+ for my $per (split /\n/) {
+ $nper++;
+ $q{$_}++ for grep { /\S/ } split(//, $per);
+ }
+ my $count = grep { $q{$_} == $nper } keys %q;
+ $sum += $count;
+}
+
+print "$sum\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my @nums = sort { $a <=> $b } <>;
+chomp @nums;
+
+my %is_listed = map { $_ => 1 } @nums;
+
+for my $i (0 .. $#nums-1) {
+ for my $j ($i .. $#nums) {
+ my $rest = 2020-$nums[$i]-$nums[$j];
+ if ($rest > 0 && $is_listed{$rest} && $rest != $nums[$i]
+ && $rest != $nums[$j]) {
+ print "$nums[$i]*$nums[$j]*$rest=", $nums[$i]*$nums[$j]*$rest, "\n";
+ last;
+ }
+ }
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my $count = 0;
+
+while (<>) {
+ my ($min, $max, $letter, $pass) = /\A(\d+)-(\d+)\s+(\S):\s+(\S+)\s*\z/;
+ if (!defined $pass) {
+ print "Divny radek $_\n";
+ next;
+ }
+
+
+ my $chars =()= ($pass =~ /$letter/g);
+
+ # print "$min-$max $letter: [$pass] - $chars\n";
+ $count++ if $chars >= $min && $chars <= $max;
+}
+
+print $count, "\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my $count = 0;
+
+while (<>) {
+ my ($min, $max, $letter, $pass) = /\A(\d+)-(\d+)\s+(\S):\s+(\S+)\s*\z/;
+ if (!defined $pass) {
+ print "Divny radek $_\n";
+ next;
+ }
+
+ no warnings 'substr';
+ # no warnings 'uninitialized';
+ $count++ if !!(substr($pass, $min-1, 1) eq $letter)
+ + !!(substr($pass, $max-1, 1) eq $letter)
+ == 1;
+}
+
+print $count, "\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my $field = do { local $/; <> };
+my $rows = $field =~ s/\s//g;
+my $flen = length $field;
+my $cols = $flen/$rows;
+
+print "Field has $flen bytes, in $rows rows and $cols cols\n";
+
+my $step = $cols + 2;
+
+my $col = 0;
+my $sum = 0;
+for my $row (0 .. $rows-1) {
+ $sum++ if substr($field, $row*$cols + $col, 1) eq '#';
+ $col += 3;
+ $col %= $cols;
+}
+print "sum=$sum\n";
+
+
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my $field = do { local $/; <> };
+my $rows = $field =~ s/\s//g;
+my $flen = length $field;
+my $cols = $flen/$rows;
+
+print "Field has $flen bytes, in $rows rows and $cols cols\n";
+
+sub slope {
+ my ($colstep, $rowstep) = @_;
+
+ $colstep += $cols;
+
+ my $col = 0;
+ my $sum = 0;
+ my $row = 0;
+ while ($row < $rows) {
+ print "row $row\n";
+ $sum++ if substr($field, $row*$cols + $col, 1) eq '#';
+ $col += $colstep;
+ $col %= $cols;
+ $row += $rowstep;
+ }
+ print "$colstep x $rowstep, sum=$sum\n";
+ return $sum;
+}
+
+print "Total: ",
+ slope(1, 1)
+ * slope(3, 1)
+ * slope(5, 1)
+ * slope(7, 1)
+ * slope(1, 2),
+ "\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+$/ = "\n\n";
+
+my $valid = 0;
+while (<>) {
+ $valid++ if (
+ grep { /^(?:byr|iyr|eyr|hgt|hcl|ecl|pid):/ }
+ split /\s+/
+ ) == 7;
+}
+
+print "Valid: $valid\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+$/ = "\n\n";
+
+my $valid = 0;
+while (<>) {
+ my $correct = 0;
+ for my $field (split /\s+/) {
+ print "$field";
+ $correct++
+ if $field =~ /\Abyr:(\d{4})\z/
+ && $1 >= 1920 && $1 <= 2002;
+ $correct++
+ if $field =~ /\Aiyr:(\d{4})\z/
+ && $1 >= 2010 && $1 <= 2020;
+ $correct++
+ if $field =~ /\Aeyr:(\d{4})\z/
+ && $1 >= 2020 && $1 <= 2030;
+ $correct++
+ if $field =~ /\Ahgt:(\d+)(cm|in)\z/
+ && ($2 eq 'cm' && $1 >= 150 && $1 <= 193
+ || $2 eq 'in' && $1 >= 59 && $1 <= 76);
+ $correct++
+ if $field =~ /\Ahcl:#[a-f0-9]{6}\z/;
+ $correct++
+ if $field =~ /\Aecl:(?:amb|blu|brn|gry|grn|hzl|oth)\z/;
+ $correct++
+ if $field =~ /\Apid:(?:\d{9})\z/;
+ print "\t$correct\n";
+ }
+ $valid++ if $correct >= 7;
+ print "\n";
+}
+
+print "Valid: $valid\n";
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+my $max = 0;
+while (<>) {
+ chomp;
+ y/FBRL/0110/;
+ my $seat = eval "0b$_";
+ $max = $seat if $max < $seat;
+}
+
+print $max, "\n";