adventofcode/2017/16/1.pl
2017-12-28 12:15:15 -05:00

20 lines
364 B
Perl

use 5.20.0;
use List::AllUtils qw/ first_index indexes /;
my @d = 'a'..'p';
for ( split ',', <> ) {
if( /s(\d+)/ ) {
splice @d, 0, 0, splice @d, -$1;
}
elsif( m#x(\d+)/(\d+)# ) {
@d[$1,$2] = @d[$2,$1];
}
elsif( m#p(.)/(.)# ) {
my @i= indexes { $_ ~~ [ $1, $2 ] } @d;
@d[@i] = @d[reverse@i];
}
}
say @d;