work on day 14

This commit is contained in:
Ben Harris 2020-12-02 01:31:01 -05:00
parent 36bb28af87
commit 1bde67a32c
Signed by: ben
GPG Key ID: 4E0AF802FFF7960C
3 changed files with 13 additions and 8 deletions

View File

@ -4,7 +4,6 @@ name: run
steps: steps:
- name: run - name: run
image: mcr.microsoft.com/dotnet/core/sdk:latest image: mcr.microsoft.com/dotnet/sdk:latest
commands: commands:
- dotnet run - dotnet run

View File

@ -6,9 +6,8 @@ namespace aoc2019
{ {
internal sealed class Day12 : Day internal sealed class Day12 : Day
{ {
private readonly List<Position> startingPositions;
private readonly List<Position> moons; private readonly List<Position> moons;
private readonly List<Position> startingPositions;
private int step; private int step;
public Day12() public Day12()

View File

@ -22,7 +22,7 @@ namespace aoc2019
private bool Consume(string chem, long quantity) private bool Consume(string chem, long quantity)
{ {
if (quantity <= 0) if (quantity <= 0)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(quantity));
if (!available!.ContainsKey(chem)) if (!available!.ContainsKey(chem))
available[chem] = 0; available[chem] = 0;
@ -59,9 +59,16 @@ namespace aoc2019
public override string Part2() public override string Part2()
{ {
available = new Dictionary<string, long> {{"ORE", 1000000000000}}; const long capacity = 1_000_000_000_000;
Consume("FUEL", long.MaxValue); available = new Dictionary<string, long> {{"ORE", capacity}};
return ""; Consume("FUEL", 1);
var oreConsumed = capacity - available["ORE"];
while (Produce("FUEL", Math.Max(1, available["ORE"] / oreConsumed)))
{
}
return $"{available["FUEL"]}";
} }
private struct Component private struct Component