]> www.fi.muni.cz Git - aoc.git/blob - 2018/31.pl
Day 25: examining the input
[aoc.git] / 2018 / 31.pl
1 #!/usr/bin/perl -w
2
3 use v5.30;
4 use strict;
5
6 local $/ = "\n\n";
7
8 my $total = 0;
9 while(<>) {
10         chomp;
11         last if !length;
12
13         my @nums = /(\d+)/g;
14         my @before = @nums[0..3];
15         my ($op, $a, $b, $c) = @nums[4..7];
16         my @after  = @nums[8..11];
17         my $match = 0;
18
19         # addr
20         $match++ if ($before[$a] + $before[$b] == $after[$c]);
21         # addi
22         $match++ if ($before[$a] + $b == $after[$c]);
23         # mulr
24         $match++ if ($before[$a] * $before[$b] == $after[$c]);
25         # muli
26         $match++ if ($before[$a] * $b == $after[$c]);
27         # bandr
28         $match++ if (($before[$a] & $before[$b]) == $after[$c]);
29         # bandi
30         $match++ if (($before[$a] & $b) == $after[$c]);
31         # borr
32         $match++ if (($before[$a] | $before[$b]) == $after[$c]);
33         # bori
34         $match++ if (($before[$a] | $b) == $after[$c]);
35         # setr
36         $match++ if ($before[$a] == $after[$c]);
37         # seti
38         $match++ if ($a == $after[$c]);
39         # gtir
40         $match++ if (($a > $before[$b] ? 1 : 0) == $after[$c]);
41         # gtri
42         $match++ if (($before[$a] > $b ? 1 : 0) == $after[$c]);
43         # gtrr
44         $match++ if (($before[$a] > $before[$b] ? 1 : 0) == $after[$c]);
45         # eqir
46         $match++ if (($a == $before[$b] ? 1 : 0) == $after[$c]);
47         # eqri
48         $match++ if (($before[$a] == $b ? 1 : 0) == $after[$c]);
49         # eqrr
50         $match++ if (($before[$a] == $before[$b] ? 1 : 0) == $after[$c]);
51
52         $total++ if $match >= 3;
53 }
54
55 say $total;