sol1.pl (814B) [raw]
1 #!/usr/bin/env perl 2 use strict; 3 use warnings; 4 5 open (my $fh, '<', 'input') or die "$!"; 6 7 my @items; 8 { 9 local $/; 10 my $content = <$fh>; 11 @items = split("\n", $content); 12 } 13 14 # HACK: don't have to compute ID for all of them--sort then compute ID 15 # 16 # BUT: we'll brute force it... 17 my @ids = map { id($_) } @items; 18 @ids = sort { $b <=> $a } @ids; 19 print $ids[0] . "\n"; 20 21 22 sub id { 23 my ($v) = @_; 24 my $id; 25 # row 26 for (my $i = 0; $i < 7; $i++) { 27 if (substr($v, $i, 1) eq 'B') { 28 $id += (2 ** (6 - $i)) * 8; 29 } else { 30 # F -- lower bound stays same, no addition 31 } 32 } 33 # col 34 for (my $i = 7; $i < 10; $i++) { 35 if (substr($v, $i, 1) eq 'R') { 36 $id += 2 ** (9 - $i); 37 } else { 38 # R 39 } 40 } 41 return $id; 42 }