clean up solution a bit
This commit is contained in:
parent
13f7672ca6
commit
f08bd0576a
@ -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…
Reference in New Issue
Block a user