Browse Source

clean up solution a bit

main
Colin McMillen 3 years ago
parent
commit
f08bd0576a
  1. 20
      2020/Day03.cs

20
2020/Day03.cs

@ -10,17 +10,15 @@ namespace AdventOfCode {
public class Day03 {
static int CountTreeIntersections(string[] lines, int dx, int dy) {
int count = 0;
int x = 0;
int y = 0;
while (y < lines.Length - 1) {
x += dx;
y += dy;
int count = 0, x = dx, y = dy;
while (y < lines.Length) {
string line = lines[y];
char tile = line[x % line.Length];
if (tile == '#') {
count++;
}
x += dx;
y += dy;
}
return count;
}
@ -32,11 +30,11 @@ namespace AdventOfCode {
static long Part2() {
string[] input = File.ReadAllLines(Util.RootDir + "day03.txt");
long result = CountTreeIntersections(input, 1, 1);
result *= CountTreeIntersections(input, 3, 1);
result *= CountTreeIntersections(input, 5, 1);
result *= CountTreeIntersections(input, 7, 1);
result *= CountTreeIntersections(input, 1, 2);
var deltas = new List<(int, int)> { (1, 1), (3, 1), (5, 1), (7, 1), (1, 2) };
long result = 1;
foreach ((int dx, int dy) in deltas) {
result *= CountTreeIntersections(input, dx, dy);
}
return result;
}

Loading…
Cancel
Save