Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.26;
- use warnings;
- # Paragraph mode, array of sections
- $/ = '';
- my @section = map {[split /\n/]} <>;
- my @dirs = split( //, $section[0][0] );
- my %graph;
- foreach ($section[1]->@*) {
- my ($label, $left, $right) = m#(\w+)#g;
- $graph{$label} = {L => $left, R => $right};
- }
- my $loc = 'AAA';
- my $steps = 0;
- while ($loc ne 'ZZZ') {
- $loc = $graph{$loc}{ $dirs[$steps % scalar(@dirs)] };
- $steps++;
- }
- say "Part 1: $steps";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement