clean up solution a bit
This commit is contained in:
parent
13f7672ca6
commit
f08bd0576a
@ -10,17 +10,15 @@ namespace AdventOfCode {
|
|||||||
public class Day03 {
|
public class Day03 {
|
||||||
|
|
||||||
static int CountTreeIntersections(string[] lines, int dx, int dy) {
|
static int CountTreeIntersections(string[] lines, int dx, int dy) {
|
||||||
int count = 0;
|
int count = 0, x = dx, y = dy;
|
||||||
int x = 0;
|
while (y < lines.Length) {
|
||||||
int y = 0;
|
|
||||||
while (y < lines.Length - 1) {
|
|
||||||
x += dx;
|
|
||||||
y += dy;
|
|
||||||
string line = lines[y];
|
string line = lines[y];
|
||||||
char tile = line[x % line.Length];
|
char tile = line[x % line.Length];
|
||||||
if (tile == '#') {
|
if (tile == '#') {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -32,11 +30,11 @@ namespace AdventOfCode {
|
|||||||
|
|
||||||
static long Part2() {
|
static long Part2() {
|
||||||
string[] input = File.ReadAllLines(Util.RootDir + "day03.txt");
|
string[] input = File.ReadAllLines(Util.RootDir + "day03.txt");
|
||||||
long result = CountTreeIntersections(input, 1, 1);
|
var deltas = new List<(int, int)> { (1, 1), (3, 1), (5, 1), (7, 1), (1, 2) };
|
||||||
result *= CountTreeIntersections(input, 3, 1);
|
long result = 1;
|
||||||
result *= CountTreeIntersections(input, 5, 1);
|
foreach ((int dx, int dy) in deltas) {
|
||||||
result *= CountTreeIntersections(input, 7, 1);
|
result *= CountTreeIntersections(input, dx, dy);
|
||||||
result *= CountTreeIntersections(input, 1, 2);
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user