ben
/
aoc
1
0
Fork 0

2015 day 3

This commit is contained in:
Ben Harris 2022-11-11 16:17:17 -05:00
parent b9932bd2da
commit 24b10ce350
3 changed files with 65 additions and 3 deletions

View File

@ -8,6 +8,7 @@ public class Test2015
[DataTestMethod]
[DataRow(typeof(Day01), "232", "1783")]
[DataRow(typeof(Day02),"1586300", "3737498")]
[DataRow(typeof(Day03), "2081", "2341")]
public void TestAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);
@ -15,6 +16,7 @@ public class Test2015
[DataTestMethod]
[DataRow(typeof(Day02), "58", "34")]
[DataRow(typeof(Day03), "2", "11")]
public void CheckTestInputs(Type dayType, string part1, string part2)
{
Day.UseTestInput = true;

View File

@ -5,11 +5,70 @@
/// </summary>
public sealed class Day03 : Day
{
public Day03() : base(2015, 3, "Puzzle Name")
public Day03() : base(2015, 3, "Perfectly Spherical Houses in a Vacuum")
{
}
public override object Part1() => "";
public override object Part1()
{
int x = 0, y = 0;
Dictionary<(int x, int y), int> map = new() { [(0, 0)] = 1 };
public override object Part2() => "";
foreach (var c in Input.First())
{
switch (c)
{
case '>': x++; break;
case '<': x--; break;
case '^': y++; break;
case 'v': y--; break;
}
if (map.ContainsKey((x, y))) map[(x, y)]++;
else map[(x, y)] = 1;
}
return map.Count(m => m.Value >= 1);
}
public override object Part2()
{
int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
Dictionary<(int x, int y), int> map = new() { [(0, 0)] = 1 };
var santaTurn = true;
foreach (var c in Input.First())
{
if (santaTurn)
{
switch (c)
{
case '>': x1++; break;
case '<': x1--; break;
case '^': y1++; break;
case 'v': y1--; break;
}
if (map.ContainsKey((x1, y1))) map[(x1, y1)]++;
else map[(x1, y1)] = 1;
}
else
{
switch (c)
{
case '>': x2++; break;
case '<': x2--; break;
case '^': y2++; break;
case 'v': y2--; break;
}
if (map.ContainsKey((x2, y2))) map[(x2, y2)]++;
else map[(x2, y2)] = 1;
}
santaTurn = !santaTurn;
}
return map.Count(m => m.Value >= 1);
}
}

View File

@ -0,0 +1 @@
^v^v^v^v^v