Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my %val = ( '=' => -2, '-' => -1, 0 => 0, 1 => 1, 2 => 2 );
- my %mod = ( 0 => 0, 1 => 1, 2 => 2, 3 => '=', 4 => '-' );
- my $sum = 0;
- while (<>) {
- chomp;
- my $pow = 1;
- my $num = 0;
- foreach my $dig (reverse split //) {
- $num += $val{$dig} * $pow;
- $pow *= 5;
- }
- $sum += $num;
- }
- print "Sum: $sum\n";
- my @part1;
- while ($sum) {
- my $dig = $sum % 5;
- unshift( @part1, $mod{$dig} );
- $sum = int( $sum / 5 ) + ($dig >= 3);
- }
- print "Part 1: ", @part1, "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement