Created
December 19, 2017 05:21
-
-
Save Aneurysm9/e716bd9923762deb661265776f3eb8ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Slurp qw/read_file/; | |
use Algorithm::Combinatorics qw/permutations combinations/; | |
use List::Util qw/max/; | |
use Data::Dumper; | |
chomp(my @input = read_file('input')); | |
my ($a, $b) = (0,0); | |
my $grid = [[]]; | |
my $i = 0; | |
foreach my $line (@input) { | |
$grid->[$i++] = [split //, $line]; | |
} | |
my ($x, $y) = (0,157); | |
my $cur = $grid->[$x][$y]; | |
my @dir = (1,0); | |
my $steps = 1; | |
sub nxt { | |
if ($grid->[$x+$dir[0]][$y+$dir[1]] ne ' ') { | |
return ($x+$dir[0], $y+$dir[1]); | |
} | |
my @left = ($dir[1], $dir[0]); | |
my @right = (-1*$dir[1], -1*$dir[0]); | |
if ($grid->[$x+$left[0]][$y+$left[1]] ne ' ') { | |
@dir = @left; | |
return ($x+$left[0], $y+$left[1]); | |
} | |
if ($grid->[$x+$right[0]][$y+$right[1]] ne ' ') { | |
@dir = @right; | |
return ($x+$right[0], $y+$right[1]); | |
} | |
return (); | |
} | |
my @seen = (); | |
while (($x, $y) = nxt()) { | |
$cur = $grid->[$x][$y]; | |
push @seen, $cur if $cur =~ m/[a-z]/i; | |
$steps++; | |
} | |
$a = join '', @seen; | |
$b = $steps; | |
print "Part One Result: $a\n"; | |
print "Part Two Result: $b\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment