Exemple #1
0
        public object Solve()
        {
            var reactions = GetReactions().ToList();

            var nanoFactory = new NanoFactory(reactions);
            
            const long availableOre = 1000000000000;
            
            long fuelCount = 0;
            var fuelCreationStep = 1000000;
            
            while (fuelCreationStep >= 1)
            {
                while (nanoFactory.OreUsed < availableOre)
                {
                    nanoFactory.Create("FUEL", fuelCreationStep);
                    fuelCount += fuelCreationStep;
                }

                if (fuelCreationStep >= 1)
                {
                    nanoFactory.Rollback();
                    fuelCount -= fuelCreationStep;
                    fuelCreationStep /= 10;
                }
            }

            return fuelCount;
        }
Exemple #2
0
        public void Test_DayFourteen_PartOne()
        {
            var fact = new NanoFactory(Path.Combine(TestHelper.TestDir, "Day14.Input.txt"));
            var fuel = new Chemical("FUEL", 1);

            fact.ProduceChemical(fuel);

            Assert.IsTrue(fact.OreRequired == 899155);
        }
        public object Solve()
        {
            var reactions = GetReactions().ToList();

            var nanoFactory = new NanoFactory(reactions);

            nanoFactory.Create("FUEL", 1);

            return(nanoFactory.OreUsed);
        }
Exemple #4
0
        public void Test_KnownReactions()
        {
            var fuel = new Chemical("FUEL", 1);

            foreach (var testTup in KnownReactions)
            {
                var fact = new NanoFactory(testTup.Item1);
                fact.ProduceChemical(fuel);
                Assert.IsTrue(fact.OreRequired == testTup.Item2);
            }
        }
Exemple #5
0
        public void TestNanoFactoryReverse(string input, long fuelProduced)
        {
            var factory = new NanoFactory(input);

            factory.Log2 = console.WriteLine;

            console.WriteLine($"ore={factory.HowMuchOreNeededForFuel(fuelProduced)}");

            var r = factory.HowMuchFuelForOre(1000000000000, 1, 1000000000000, 50);

            Assert.Equal(fuelProduced, r);
        }
Exemple #6
0
        public void TestRawMaterial(List <string> reactions, int expectedORE, long maxFuel)
        {
            var factory = new NanoFactory(reactions);
            var raw     = factory.GetRawMaterialFor(new ReactionTerm("FUEL", 1));
            var ore     = raw.FirstOrDefault(e => e.Element == "ORE");

            Assert.IsTrue(ore != null);
            Assert.IsTrue(ore.Quantity == expectedORE);

            var maxProduction = factory.GetProductionCapacity("FUEL", new ReactionTerm("ORE", 1000000000000));

            Assert.IsTrue(maxProduction == maxFuel);
        }
Exemple #7
0
        public void TestNanoFactory(string input, int oreExpected)
        {
            var factory = new NanoFactory(input);

            factory.Log = console.WriteLine;

            factory.WhatsNeeded(1, "FUEL");

            Assert.Equal(oreExpected, -factory.Supply["ORE"]);
            foreach (var kv in factory.Supply)
            {
                if (kv.Key != "ORE")
                {
                    Assert.True(kv.Value >= 0);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Execution function for Day 14
        /// </summary>
        public void Execute14()
        {
            UserActionAsync(() =>
            {
                WriteToConsole("Start execution of Day14");
                var parser    = GetInputParser("Day14Input.txt");
                var reactions = parser.GetInputData();

                var factory = new NanoFactory(reactions);
                var raw     = factory.GetRawMaterialFor(new ReactionTerm("FUEL", 1));
                var ore     = raw.FirstOrDefault(e => e.Element == "ORE");

                WriteToConsole($"In order to produce one unit of FUEL {ore.Quantity} units ORE are needed");

                var maxProduction = factory.GetProductionCapacity("FUEL", new ReactionTerm("ORE", 1000000000000));

                WriteToConsole($"With 1000000000000 of ORE {maxProduction} units FUEL might be produced");
            });
        }
Exemple #9
0
        protected override long Part1(string[] input)
        {
            var oreNeeded = new NanoFactory(input).ReduceFuelToOre(1);

            return(oreNeeded);
        }
Exemple #10
0
        public static int SolvePart2(string[] input)
        {
            var factory = new NanoFactory(input);

            return(factory.CalculateMaxFuelProduction());
        }
Exemple #11
0
        public static int SolvePart1(string[] input)
        {
            var factory = new NanoFactory(input);

            return(factory.CalculateOreDemand());
        }