ben
/
aoc
1
0
Fork 0

2023 day 6
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Ben Harris 2023-12-06 12:18:18 -05:00
parent b254c48ec4
commit 5c2434c153
4 changed files with 61 additions and 0 deletions

View File

@ -10,6 +10,7 @@ public class Test2023
[DataRow(typeof(Day02), "2476", "54911")]
[DataRow(typeof(Day03), "522726", "81721933")]
[DataRow(typeof(Day04), "20117", "13768818")]
[DataRow(typeof(Day06), "505494", "2362299")]
public void CheckAllDays(Type dayType, string part1, string part2) =>
Common.CheckDay(dayType, part1, part2);
@ -19,6 +20,7 @@ public class Test2023
[DataRow(typeof(Day03), "4361", "467835")]
[DataRow(typeof(Day04), "13", "30")]
// [DataRow(typeof(Day05), "35", "")]
[DataRow(typeof(Day06), "288", "71503")]
public void CheckTestInputs(Type dayType, string part1, string part2) =>
Common.CheckDay(dayType, part1, part2, true);
}

55
AOC2023/Day06.cs Normal file
View File

@ -0,0 +1,55 @@
namespace AOC2023;
public class Day06() : Day(2023, 6, "Wait For It")
{
private readonly List<(int time, int distance)> _races = [];
public override void ProcessInput()
{
var input = Input.Select(l =>
l.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
.Skip(1)
.Select(int.Parse)
.ToList()
).ToList();
for (var i = 0; i < input[0].Count; i++)
_races.Add((input[0][i], input[1][i]));
}
public override object Part1() =>
_races.Select(race =>
{
var cnt = 0;
for (var speed = 1; speed < race.time; speed++)
if (speed * (race.time - speed) > race.distance)
cnt++;
return cnt;
}).Aggregate(1, (a, b) => a * b);
public override object Part2()
{
var input = Input.ToList();
var time = ulong.Parse(input[0].Replace(" ", "").Replace("Time:", ""));
var distance = ulong.Parse(input[1].Replace(" ", "").Replace("Distance:", ""));
var shortestPress = 0ul;
for (var speed = 0ul; speed < time; speed++)
if (speed * (time - speed) > distance)
{
shortestPress = speed;
break;
}
var longestPress = 0ul;
for (var speed = time; speed > 0; speed--)
if (speed * (time - speed) > distance)
{
longestPress = speed;
break;
}
return longestPress - shortestPress + 1;
}
}

View File

@ -0,0 +1,2 @@
Time: 40 82 91 66
Distance: 277 1338 1349 1063

View File

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200