Created
December 3, 2015 10:53
-
-
Save phroggyy/96a3abf5841b6165b9d6 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
<?php | |
$input = str_split(file('i')[0]); | |
$map = [ | |
'^' => [1,0], | |
'>' => [0,1], | |
'v' => [-1,0], | |
'<' => [0,-1], | |
]; | |
$locations = [[0,0]]; | |
foreach ($input as $instruction) { | |
$a=end($locations);reset($locations); | |
$b=$map[$instruction]; | |
$locations[] = [$a[0]+$b[0],$a[1]+$b[1]]; | |
} | |
echo count(array_unique(array_values($locations), SORT_REGULAR)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment