prettier
This commit is contained in:
parent
b1cf1719a3
commit
c7b8b6a8c8
@ -4,21 +4,22 @@ package Part1;
|
||||
|
||||
use List::AllUtils qw/ /;
|
||||
|
||||
sub parse_input($input) {
|
||||
sub parse_input ($input) {
|
||||
my ( $directions, undef, @nodes ) = split "\n", $input;
|
||||
|
||||
$directions = [ split "", $directions =~ s/R/1/gr =~ s/L/0/gr ];
|
||||
|
||||
my %nodes;
|
||||
|
||||
for(@nodes) {
|
||||
for (@nodes) {
|
||||
my @n = /([A-Z]+)/g;
|
||||
$nodes{ shift @n } = \@n;
|
||||
}
|
||||
|
||||
return {
|
||||
directions => $directions,
|
||||
nodes => \%nodes };
|
||||
nodes => \%nodes
|
||||
};
|
||||
}
|
||||
|
||||
sub solution_1 ($input) {
|
||||
@ -30,10 +31,11 @@ sub solution_1 ($input) {
|
||||
my $next_index = 0;
|
||||
my $current = 'AAA';
|
||||
|
||||
while( $current ne 'ZZZ') {
|
||||
while ( $current ne 'ZZZ' ) {
|
||||
$visited++;
|
||||
|
||||
$current = $nodes{$current}->[ $directions[$next_index++ % @directions ] ];
|
||||
$current =
|
||||
$nodes{$current}->[ $directions[ $next_index++ % @directions ] ];
|
||||
}
|
||||
|
||||
return $visited;
|
||||
|
@ -6,7 +6,6 @@ use Part1;
|
||||
|
||||
use List::AllUtils qw/ /;
|
||||
|
||||
|
||||
sub solution_2 ($input) {
|
||||
...;
|
||||
}
|
||||
|
@ -13,13 +13,14 @@ my %solutions = deserialize_file('solutions.yml')->%*;
|
||||
|
||||
my $parsed = Part1::parse_input($example);
|
||||
|
||||
use DDP; p $parsed;
|
||||
use DDP;
|
||||
p $parsed;
|
||||
|
||||
is $parsed->{directions} => [1,0];
|
||||
is $parsed->{nodes}{AAA} => [ qw/ BBB CCC /];
|
||||
is $parsed->{directions} => [ 1, 0 ];
|
||||
is $parsed->{nodes}{AAA} => [qw/ BBB CCC /];
|
||||
|
||||
is Part1::solution_1($example) => 2;
|
||||
is Part1::solution_1(<<'END') => 6;
|
||||
is Part1::solution_1($example) => 2;
|
||||
is Part1::solution_1(<<'END') => 6;
|
||||
LLR
|
||||
|
||||
AAA = (BBB, BBB)
|
||||
@ -27,11 +28,9 @@ BBB = (AAA, ZZZ)
|
||||
ZZZ = (ZZZ, ZZZ)
|
||||
END
|
||||
|
||||
SKIP: {
|
||||
SKIP: {
|
||||
# skip "not there yet" if $solutions{1} eq 'TODO';
|
||||
is Part1::solution_1($input) => $solutions{1};
|
||||
}
|
||||
|
||||
|
||||
|
||||
done_testing;
|
||||
|
Loading…
Reference in New Issue
Block a user