Skip to content

Commit

Permalink
Tidied up the day 23.2 code a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jongeorge1 committed Dec 9, 2019
1 parent fb27e6e commit d0a136c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions AoC2018.Solutions/Day23/Part02.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public string Solve(string input)
.Select(x => new Nanobot(x))
.ToList();

(int X, int Y, int Z) bestLocation = (0, 0, 0);
int botsInRangeAtBestLocation = 0;
int bestLocationDistanceFromOrigin = int.MaxValue;

int granularity = bots.Count < 50 ? 1 : (int)Math.Pow(2, 22);

(int MinX, int MaxX, int MinY, int MaxY, int MinZ, int MaxZ) bounds =
(bots.Min(bot => bot.Position.X),
bots.Max(bot => bot.Position.X),
Expand Down Expand Up @@ -50,6 +44,12 @@ public string Solve(string input)
};

var boxQueue = new SimplePriorityQueue<Box>();

// We're using the nanobots in range metric to order the priority queue. We have negate it
// because we want the highest first. This would likely not work for all inputs - if there
// were multiple points with the same number of nanobots in range we'd need to deal with that.
// We'd likely do that by implementing a custom comparer that sorted on nanobots, then on box size
// (largest first) and on distance from the origin (closest first).
boxQueue.Enqueue(box, -box.NanobotsInRange);

while (boxQueue.Count > 0)
Expand Down

0 comments on commit d0a136c

Please sign in to comment.