Thanks for the reprieve.
This commit is contained in:
2023-12-06 07:47:14 -06:00
parent a64c43e2e6
commit 11a8465853
4 changed files with 73 additions and 0 deletions

View File

@ -40,6 +40,8 @@
<EmbeddedResource Include="inputs\04a.txt" /> <EmbeddedResource Include="inputs\04a.txt" />
<EmbeddedResource Include="inputs\05.txt" /> <EmbeddedResource Include="inputs\05.txt" />
<EmbeddedResource Include="inputs\05a.txt" /> <EmbeddedResource Include="inputs\05a.txt" />
<EmbeddedResource Include="inputs\06.txt" />
<EmbeddedResource Include="inputs\06a.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

2
inputs/06.txt Normal file
View File

@ -0,0 +1,2 @@
Time: 44 70 70 80
Distance: 283 1134 1134 1491

2
inputs/06a.txt Normal file
View File

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

67
src/06.cs Normal file
View File

@ -0,0 +1,67 @@
namespace aoc2023;
internal class Day06 : Day
{
private List<int> times = new();
private List<int> dists = new();
private long time = 0;
private long dist = 0;
internal override void Parse()
{
var lines = Util.Parsing.ReadAllLines($"{GetDay()}").ToList();
var timeline = lines[0].Split(':');
times = timeline[1].Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
time = long.Parse(timeline[1].Replace(" ", ""));
var distline = lines[1].Split(':');
dists = distline[1].Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
dist = long.Parse(distline[1].Replace(" ", ""));
}
internal override string Part1()
{
long total = 1;
for (int i = 0; i < times.Count; i++)
{
long numWins = 0;
bool hasWon = false;
for (int chargetime = 1; chargetime < times[i]; chargetime++)
{
var d = chargetime * (times[i] - chargetime);
if (d > dists[i])
{
hasWon = true;
numWins++;
}
else if (hasWon)
{
break;
}
}
total *= numWins;
}
return $"Multiplied number of wins total: <+white>{total}";
}
internal override string Part2()
{
long numWins = 0;
bool hasWon = false;
for (int chargetime = 1; chargetime < time; chargetime++)
{
var d = chargetime * (time - chargetime);
if (d > dist)
{
hasWon = true;
numWins++;
}
else if (hasWon)
{
break;
}
}
return $"Number of wins with correct kerning: <+white>{numWins}";
}
}