Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- use List::Util qw(product all);
- my @DIM = (101, 103);
- $; = ',';
- my @robots = map { [m#([-0-9]+,[-0-9]+)#g] } <>;
- my %moved;
- foreach my $robot (@robots) {
- my ($pos, $vel) = map {[split /,/]} @$robot;
- @$pos = map { ($pos->[$_] + 100 * $vel->[$_]) % $DIM[$_] } (0,1);
- $moved{ $pos->[0], $pos->[1] }++;
- }
- my %quads;
- foreach my $robot (keys %moved) {
- my @pos = split( $;, $robot );
- my @quad = map { $pos[$_] <=> int($DIM[$_] / 2) } (0,1);
- $quads{ $quad[0], $quad[1] } += $moved{$robot} if (all {$_} @quad);
- }
- say "Part 1: ", product values %quads;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement