Skip to content

Instantly share code, notes, and snippets.

@phroggyy
Created December 3, 2015 10:53
Show Gist options
  • Save phroggyy/96a3abf5841b6165b9d6 to your computer and use it in GitHub Desktop.
Save phroggyy/96a3abf5841b6165b9d6 to your computer and use it in GitHub Desktop.
<?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