Ejemplo n.º 1
0
        public static string secondPuzzle(string location)
        {
            string[] lines    = File.ReadAllLines(@location, Encoding.UTF8);
            Refinery refinery = new Refinery(lines);
            long     maxFuel  = 0;
            int      factor   = 10000;
            Dictionary <string, long> oldExtra = null;
            long oldNeededOre = 0;

            while (factor >= 1)
            {
                while (refinery.NeededOre < 1000000000000)
                {
                    oldExtra     = new Dictionary <string, long>(refinery.Extra);
                    oldNeededOre = refinery.NeededOre;
                    refinery.ProduceMolecule(new Molecule()
                    {
                        Name = "FUEL", Amount = factor
                    });
                    maxFuel += factor;
                }
                //produced too much, reset old state and donwgrade factor / 10
                if (factor >= 1)
                {
                    refinery.Extra     = new Dictionary <string, long>(oldExtra);
                    refinery.NeededOre = oldNeededOre;
                    maxFuel           -= factor;
                    factor            /= 10;
                }
            }
            return(maxFuel.ToString());
        }
Ejemplo n.º 2
0
        public static string firstPuzzle(string location)
        {
            string[] lines    = File.ReadAllLines(@location, Encoding.UTF8);
            Refinery refinery = new Refinery(lines);

            refinery.ProduceMolecule(new Molecule()
            {
                Name = "FUEL", Amount = 1
            });
            return(refinery.NeededOre.ToString());
        }