aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

sol1.pl (314B) [raw]


      1 #!/usr/bin/env perl
      2 # idea:
      3 #   HAS to be O(N) because have to check each item in worst case
      4 use strict;
      5 use warnings;
      6 
      7 my %seen;
      8 while (<>) {
      9     chomp;
     10     my $comp = 2020 - $_;
     11     if (exists $seen{$comp}) {
     12         print $_ * $comp . "\n";
     13         exit(0);
     14     } else {
     15         $seen{$_} = 1;
     16     }
     17 }
     18 exit(1);