advent2022

Advent of Code 2022 Solutions
git clone https://todayiwilllaunchmyinfantsonintoorbit.com/advent2022.git
Log | Files | Refs

2b.pl (852B)


      1 #!/usr/bin/perl
      2 
      3 my $score = 0;
      4 while (<>) {
      5     chomp;
      6     /^([ABC]) ([XYZ])$/ || die "Fuck!";
      7     (my $them, $meInst) = (ord($1) - 64, $2);
      8     my $me;
      9     print "$meInst\n";
     10     if ($meInst eq "X") {
     11         print "They win\n";
     12         $me = ($them == 1) ? 3 : $them - 1;
     13     } elsif ($meInst eq "Y") {
     14         print "Tie\n";
     15         $me = $them;
     16     } else {
     17         print "I win\n";
     18         $me = ($them % 3) + 1; 
     19     }
     20     $score += $me;
     21     if ((($them > $me) && !($me == 1 && $them == 3))|| ($them == 1 && $me == 3)) {
     22         # Nothing!
     23         print "Them\n";
     24     } elsif (($me > $them) || ($me == 1 && $them == 3)) {
     25         print "Me\n";
     26         $score += 6;
     27     } elsif ($me == $them) {
     28         print "Tie\n";
     29         $score += 3;
     30     } else {
     31         print "What the fuck\n";
     32     }
     33     print "Score is now $score\n";
     34 }
     35 print "$score\n";