Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my %table1 = ( # Rock Paper Scissors
- 'A' => { 'X' => 4, 'Y' => 8, 'Z' => 3 }, # Rock
- 'B' => { 'X' => 1, 'Y' => 5, 'Z' => 9 }, # Paper
- 'C' => { 'X' => 7, 'Y' => 2, 'Z' => 6 }, # Scissors
- );
- my %table2 = ( # Lose Draw Win
- 'A' => { 'X' => 3, 'Y' => 4, 'Z' => 8 }, # Rock
- 'B' => { 'X' => 1, 'Y' => 5, 'Z' => 9 }, # Paper
- 'C' => { 'X' => 2, 'Y' => 6, 'Z' => 7 }, # Scissors
- );
- my $part1 = 0;
- my $part2 = 0;
- while (<>) {
- my ($a, $b) = split;
- $part1 += $table1{$a}{$b};
- $part2 += $table2{$a}{$b};
- }
- print "Part 1: $part1\n";
- print "Part 2: $part2\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement