main
Yanick Champoux 2017-12-11 10:33:28 -05:00
parent a10c861f4c
commit 91a8bf6112
4 changed files with 73 additions and 0 deletions

21
10/1.pl Normal file
View File

@ -0,0 +1,21 @@
use 5.20.0;
my @commands = split ',', scalar <>;
my $skip = 0;
my $i = 0;
my @array = 0..255;
for my $c ( @commands ) {
@array[0..$c-1] = @array[ reverse 0..$c-1];
push @array, shift @array for 1..$c + $skip++;
$i += $c + $skip-1;
say "@array";
warn "index: $i";
}
warn $i;
unshift @array, pop @array for 1..($i%@array);
say "@array";
say $array[0] * $array[1];

1
10/input.txt Normal file
View File

@ -0,0 +1 @@
106,16,254,226,55,2,1,166,177,247,93,0,255,228,60,36

50
11/1.pl Normal file
View File

@ -0,0 +1,50 @@
use 5.20.0;
my $path = <>;
chomp $path;
my %path;
$path{$_}++ for split ',', $path;
use DDP;
my %d = (
n => [ 0,1],
s => [ 0,-1],
e => [ 1, 0],
w => [ -1,0],
);
use experimental 'postderef', 'signatures';
for my $y ( qw/ n s / ){
for my $e ( qw/ e w / ){
$d{"$y$e"} = [ map { $_/2 } add( $d{$y}, $d{$e} )->@* ];
}
}
my $position = [0,0];
use List::AllUtils qw/ reduce min /;
$position = reduce { add($a,$d{$b}) } $position, split ',', $path;
p %d;
p %path;
p $position;
my @position = map { abs } @$position;
my $to_go = 0;
my $i = min @position;
$to_go = 2 * $i;
@position = map { $_ - $i } @position;
$to_go += 2 * $position[0] + $position[1];
say $to_go;
sub add($x,$y) {
[ map { $x->[$_] + $y->[$_] } 0..1 ]
}

1
11/input.txt Normal file

File diff suppressed because one or more lines are too long