Skip to content

Instantly share code, notes, and snippets.

@jamosaur
Last active December 3, 2015 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamosaur/7665a3d4c7aa5eef64f9 to your computer and use it in GitHub Desktop.
Save jamosaur/7665a3d4c7aa5eef64f9 to your computer and use it in GitHub Desktop.
<?php
$i = file_get_contents('i');
//$i = '^>v<';
$x = $rx = 0;
$y = $ry = 0;
foreach (str_split($i) as $n => $dir) {
switch ($dir) {
case '^':
($n % 2 == 0) ? $x++ : $rx++;
break;
case '<':
($n % 2 == 0) ? $y-- : $ry--;
break;
case '>':
($n % 2 == 0) ? $y++ : $ry++;
break;
default:
($n % 2 == 0) ? $x-- : $rx--;
}
($n % 2 == 0) ? $arr[0][$n] = "$x,$y" : $arr[1][$n] = "$rx,$ry";
}
$s = count(array_unique($arr[0]));
$r = count(array_unique($arr[1]));
echo "santa: ".$s.PHP_EOL;
echo "robo: ".$r.PHP_EOL;
echo "Total: ". (count(array_unique(array_merge($arr[0], $arr[1])))+1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment