X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=27.pl;fp=27.pl;h=a17a3829db27b50f461959ca4328f59c58add6cc;hb=0c26b846783563f208ecedc83fe18f12f8f24293;hp=0000000000000000000000000000000000000000;hpb=b957ac325434a1623becbe1850127821a94c38fe;p=aoc2020.git diff --git a/27.pl b/27.pl new file mode 100755 index 0000000..a17a382 --- /dev/null +++ b/27.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +use strict; +no warnings 'portable'; + +my @mem; + +my ($andm, $orm); +while (<>) { + chomp; + if (/mask = (\S+)/) { + ($orm, $andm) = ($1, $1); + $andm =~ s/X/1/g; $andm = oct "0b$andm"; + $orm =~ s/X/0/g; $orm = oct "0b$orm"; + print "andm=$andm\n orm=$orm\n"; + next; + } + if (/mem\[(\d+)\] = (\d+)/) { + $mem[$1] = ($2 | $orm) & $andm; + print "mem[$1] = $2 => $mem[$1]\n"; + } +} + +my $sum; +for (@mem) { $sum += $_ if defined $_ }; +print "Sum=$sum\n";