Created
December 3, 2015 14:36
-
-
Save johnboker/96c73af812a349442551 to your computer and use it in GitHub Desktop.
This file contains 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
// part 1 | |
var input = "<input here>"; | |
var visited = new List<Point> { new Point(0, 0) }; | |
var x = 0; | |
var y = 0; | |
foreach (var d in input) | |
{ | |
if (d == 'v') y--; | |
if (d == '>') x++; | |
if (d == '^') y++; | |
if (d == '<') x--; | |
if (!visited.Any(a => a.X == x && a.Y == y)) | |
{ | |
visited.Add(new Point(x, y)); | |
} | |
} | |
// part 2 | |
var input = "<input here>"; | |
var visited = new List<Point> { new Point(0, 0) }; | |
var x1 = 0; | |
var y1 = 0; | |
var x2 = 0; | |
var y2 = 0; | |
var i = 0; | |
foreach (var d in input) | |
{ | |
var x = 0; | |
var y = 0; | |
if (i % 2 == 0) | |
{ | |
if (d == 'v') y1--; | |
if (d == '>') x1++; | |
if (d == '^') y1++; | |
if (d == '<') x1--; | |
x = x1; | |
y = y1; | |
} | |
else | |
{ | |
if (d == 'v') y2--; | |
if (d == '>') x2++; | |
if (d == '^') y2++; | |
if (d == '<') x2--; | |
x = x2; | |
y = y2; | |
} | |
if (!visited.Any(a => a.X == x && a.Y == y)) | |
{ | |
visited.Add(new Point(x, y)); | |
} | |
i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment