Skip to content

Instantly share code, notes, and snippets.

@phroggyy
Created December 3, 2015 11:07
Show Gist options
  • Save phroggyy/752aa296ec5d3edde7cb to your computer and use it in GitHub Desktop.
Save phroggyy/752aa296ec5d3edde7cb to your computer and use it in GitHub Desktop.
<?php
$f = str_split(file('i')[0]);
$map = [
'^' => [1,0],
'>' => [0,1],
'v' => [-1,0],
'<' => [0, -1],
];
$s = $r = [[0,0]];
foreach ($f as $k => $i) {
$p=$k%2 ? 's' : 'r' ;
$a=end($$p);reset($$p);
$b=$map[$i];
array_push($$p, [$a[0]+$b[0],$a[1]+$b[1]]);
}
echo count(array_unique(array_merge($s,$r), SORT_REGULAR));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment