part 1 wip
This commit is contained in:
parent
c7b8b6a8c8
commit
692e0301e7
@ -12,7 +12,7 @@ sub parse_input ($input) {
|
||||
my %nodes;
|
||||
|
||||
for (@nodes) {
|
||||
my @n = /([A-Z]+)/g;
|
||||
my @n = /([A-Z\d]+)/g;
|
||||
$nodes{ shift @n } = \@n;
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,32 @@ package Part2;
|
||||
|
||||
use Part1;
|
||||
|
||||
use List::AllUtils qw/ /;
|
||||
use List::AllUtils qw/all /;
|
||||
|
||||
sub solution_2 ($input) {
|
||||
...;
|
||||
my $p = Part1::parse_input($input);
|
||||
my @directions = $p->{directions}->@*;
|
||||
my %nodes = $p->{nodes}->%*;
|
||||
|
||||
my $visited = 0;
|
||||
my $next_index = 0;
|
||||
my @current = grep { /A$/ } keys %nodes;
|
||||
|
||||
until ( all { /Z$/ } @current ) {
|
||||
# use DDP; p @current;
|
||||
# my $foo = <>;
|
||||
$visited++;
|
||||
|
||||
@current = map {
|
||||
$nodes{$_}->[ $directions[ $next_index % @directions ] ]
|
||||
} @current;
|
||||
$next_index++;
|
||||
}
|
||||
|
||||
return $visited;
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
1;
|
||||
|
@ -6,6 +6,7 @@ use Path::Tiny;
|
||||
use File::Serialize;
|
||||
|
||||
use Part1;
|
||||
use Part2;
|
||||
|
||||
my $input = path('input')->slurp;
|
||||
my $example = path('example')->slurp;
|
||||
@ -13,9 +14,6 @@ my %solutions = deserialize_file('solutions.yml')->%*;
|
||||
|
||||
my $parsed = Part1::parse_input($example);
|
||||
|
||||
use DDP;
|
||||
p $parsed;
|
||||
|
||||
is $parsed->{directions} => [ 1, 0 ];
|
||||
is $parsed->{nodes}{AAA} => [qw/ BBB CCC /];
|
||||
|
||||
@ -33,4 +31,5 @@ SKIP: {
|
||||
is Part1::solution_1($input) => $solutions{1};
|
||||
}
|
||||
|
||||
|
||||
done_testing;
|
||||
|
@ -3,11 +3,27 @@ use 5.38.0;
|
||||
use Test2::V0;
|
||||
|
||||
use Path::Tiny;
|
||||
use File::Serialize;
|
||||
|
||||
use Part2;
|
||||
|
||||
my $input = path('input')->slurp;
|
||||
my $example = path('example')->slurp;
|
||||
my %solutions = deserialize_file('solutions.yml')->%*;
|
||||
|
||||
is Part2::solution_2($input) => 'TODO';
|
||||
is Part2::solution_2(<<'END') => 6;
|
||||
LR
|
||||
|
||||
11A = (11B, XXX)
|
||||
11B = (XXX, 11Z)
|
||||
11Z = (11B, XXX)
|
||||
22A = (22B, XXX)
|
||||
22B = (22C, 22C)
|
||||
22C = (22Z, 22Z)
|
||||
22Z = (22B, 22B)
|
||||
XXX = (XXX, XXX)
|
||||
END
|
||||
|
||||
is Part2::solution_2($input) => $solutions{2};
|
||||
|
||||
done_testing;
|
||||
|
Loading…
Reference in New Issue
Block a user