about summary refs log tree commit diff
path: root/Day14.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Day14.cs')
-rw-r--r--Day14.cs15
1 files changed, 11 insertions, 4 deletions
diff --git a/Day14.cs b/Day14.cs
index e4c46e8..1aff2bf 100644
--- a/Day14.cs
+++ b/Day14.cs
@@ -22,7 +22,7 @@ namespace aoc2019
         private bool Consume(string chem, long quantity)
         {
             if (quantity <= 0)
-                throw new ArgumentOutOfRangeException();
+                throw new ArgumentOutOfRangeException(nameof(quantity));
 
             if (!available!.ContainsKey(chem))
                 available[chem] = 0;
@@ -59,9 +59,16 @@ namespace aoc2019
 
         public override string Part2()
         {
-            available = new Dictionary<string, long> {{"ORE", 1000000000000}};
-            Consume("FUEL", long.MaxValue);
-            return "";
+            const long capacity = 1_000_000_000_000;
+            available = new Dictionary<string, long> {{"ORE", capacity}};
+            Consume("FUEL", 1);
+
+            var oreConsumed = capacity - available["ORE"];
+            while (Produce("FUEL", Math.Max(1, available["ORE"] / oreConsumed)))
+            {
+            }
+
+            return $"{available["FUEL"]}";
         }
 
         private struct Component