5 my $map; { local $/; $map = <>; }
7 my (@score, %seen, $round);
9 $seen{$map} = $round++;
12 do { # rotate the map:
13 $map1 .= join('', reverse $map =~ /^./gm) . "\n"
14 } while $map =~ s/^.//gm;
16 1 while $map =~ s/O(\.+)/$1O/g; # move O's to the right
18 $score[$round] +=()= substr($map, pos($map)) =~ /\n/g
22 my $remains = (1000000000 - $round) % ($round - $seen{$map});
23 say $score[$seen{$map} + $remains];