Skip to content

Commit

Permalink
day 22 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 22, 2024
1 parent 4d27595 commit da57d33
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions AdventOfCode/Day22.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ public override ValueTask<string> Solve_2()
{
long[] numbers = File.ReadAllLines(InputFilePath).Select(long.Parse).ToArray();


Dictionary<(int, int, int, int), int> bananas = new Dictionary<(int, int, int, int), int>();
Dictionary<(int, int, int, int), int> allBananas = new Dictionary<(int, int, int, int), int>();
foreach (long n in numbers)
{
Dictionary<(int, int, int, int), int> bananas = new Dictionary<(int, int, int, int), int>();

(int, int)[] changes = GetPricesWithChanges(n, 2000);

for (int i = 0; i < changes.Length - 3; ++i)
{
if (!bananas.TryAdd((changes[i].Item2, changes[i+1].Item2, changes[i+2].Item2, changes[i+3].Item2), changes[i+3].Item1))
bananas.TryAdd((changes[i].Item2, changes[i + 1].Item2, changes[i + 2].Item2, changes[i + 3].Item2), changes[i + 3].Item1);
}

foreach(var kv in bananas)
{
if (!allBananas.TryAdd(kv.Key, kv.Value))
{
bananas[(changes[i].Item2, changes[i + 1].Item2, changes[i + 2].Item2, changes[i + 3].Item2)] += changes[i + 3].Item1;
allBananas[kv.Key] += kv.Value;
}
}
}

int max = bananas.Max(b => b.Value);
int max = allBananas.Max(b => b.Value);

return new(max.ToString());
}
Expand Down

0 comments on commit da57d33

Please sign in to comment.