ben
/
aoc
1
0
Fork 0

2016 day 2
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2023-11-23 11:35:08 -05:00
parent e8fa4d8b55
commit c60fe81fb1
4 changed files with 65 additions and 5 deletions

View File

@ -64,8 +64,8 @@ public abstract class Day(int year, int day, string puzzleName)
throw new ApplicationException("no days found");
}
UseTestInput = args is [_, "--test"] or ["--test", ..];
var verbose = args is [_, "--verbose"] or ["--verbose", ..];
UseTestInput = args.Contains("--test");
var verbose = args.Contains("--verbose");
if (args.Length > 0 && int.TryParse(args[0], out var dayNum))
{

View File

@ -7,8 +7,16 @@ public class Test2016
{
[DataTestMethod]
[DataRow(typeof(Day01), "300", "159")]
[DataRow(typeof(Day02), "76792", "A7AC3")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);
}
[DataTestMethod]
[DataRow(typeof(Day02), "1985", "5DB3")]
public void CheckTestInputs(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2, true);
}
}

View File

@ -9,7 +9,55 @@ public sealed class Day02() : Day(2016, 2, "Puzzle Name")
{
}
public override object Part1() => "";
public override object Part1()
{
List<int> answer = new();
var location = (x: 1, y: 1);
public override object Part2() => "";
}
foreach (var line in Input)
{
location = line.Aggregate(location, (c, instruction) => instruction switch
{
'U' => c with { y = c.y == 0 ? c.y : c.y - 1 },
'D' => c with { y = c.y == 2 ? c.y : c.y + 1 },
'L' => c with { x = c.x == 0 ? c.x : c.x - 1 },
'R' => c with { x = c.x == 2 ? c.x : c.x + 1 },
_ => throw new ArgumentException("invalid direction", nameof(instruction))
});
answer.Add(1 + location.x + location.y * 3);
}
return string.Join("", answer);
}
public override object Part2()
{
var keyPad = new[,]
{
{ '\0', '\0', '1', '\0', '\0' },
{ '\0', '2', '3', '4', '\0' },
{ '5', '6', '7', '8', '9' },
{ '\0', 'A', 'B', 'C', '\0' },
{ '\0', '\0', 'D', '\0', '\0' },
};
var location = (x: 0, y: 2);
List<char> answer = new();
foreach (var line in Input)
{
location = line.Aggregate(location, (c, instruction) => instruction switch
{
'U' => c with { y = c.y == 0 || keyPad[c.y - 1, c.x] == '\0' ? c.y : c.y - 1 },
'D' => c with { y = c.y == 4 || keyPad[c.y + 1, c.x] == '\0' ? c.y : c.y + 1 },
'L' => c with { x = c.x == 0 || keyPad[c.y, c.x - 1] == '\0' ? c.x : c.x - 1 },
'R' => c with { x = c.x == 4 || keyPad[c.y, c.x + 1] == '\0' ? c.x : c.x + 1 },
_ => throw new ArgumentException("invalid direction", nameof(instruction))
});
answer.Add(keyPad[location.y, location.x]);
}
return string.Join("", answer);
}
}

View File

@ -0,0 +1,4 @@
ULL
RRDDD
LURDL
UUUUD