Skip to content

Commit

Permalink
day12: make part2 more like part1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanperret committed Dec 12, 2020
1 parent 39a76fa commit 3740a4c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions day12/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main(string[] args)
var lines = File.ReadAllLines("input.txt");

int x = 0, y = 0;
int wx = 10, wy = 1;
int dx = 10, dy = 1;
foreach (string line in lines)
{
char move = line[0];
Expand All @@ -25,40 +25,40 @@ static void Main(string[] args)
{
case "L180":
case "R180":
wx = -wx;
wy = -wy;
dx = -dx;
dy = -dy;
break;
case "L270":
case "R90":
(wx, wy) = (wy, -wx);
(dx, dy) = (dy, -dx);
break;
case "R270":
case "L90":
(wx, wy) = (-wy, wx);
(dx, dy) = (-dy, dx);
break;
default:
switch (move)
{
case 'F':
x += dist * wx;
y += dist * wy;
x += dist * dx;
y += dist * dy;
break;
case 'N':
wy += dist;
dy += dist;
break;
case 'S':
wy -= dist;
dy -= dist;
break;
case 'W':
wx -= dist;
dx -= dist;
break;
case 'E':
wx += dist;
dx += dist;
break;
}
break;
}
W($"{line} {x} {y} {wx} {wy} {Math.Abs(x) + Math.Abs(y)}");
W($"{line} {x} {y} {dx} {dy} {Math.Abs(x) + Math.Abs(y)}");
}
}
}

0 comments on commit 3740a4c

Please sign in to comment.