]> www.fi.muni.cz Git - aoc2020.git/blob - 2.pl
Task 9 Perl Golf-style
[aoc2020.git] / 2.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @nums = sort { $a <=> $b } <>;
6 chomp @nums;
7
8 my %is_listed = map { $_ => 1 } @nums;
9
10 for my $i (0 .. $#nums-1) {
11         for my $j ($i .. $#nums) {
12                 my $rest = 2020-$nums[$i]-$nums[$j];
13                 if ($rest > 0 && $is_listed{$rest} && $rest != $nums[$i]
14                         && $rest != $nums[$j]) {
15                         print "$nums[$i]*$nums[$j]*$rest=", $nums[$i]*$nums[$j]*$rest, "\n";
16                         last;
17                 }
18         }
19 }
20