public void Day14Part2_TestSolution()
        {
            string[] map = DayDataUtilities.ReadLinesFromFile("day14.txt");
            Assert.NotNull(map);
            Assert.Equal(63, map.Length);

            RefineryNanoFactory sut = new RefineryNanoFactory();

            foreach (string recipe in map)
            {
                sut.ParseRecipe(recipe);
            }
            Assert.Equal(63, sut.Chemicals.Count);
            long fuel    = 0;
            long oreCost = 0;

            while (oreCost < 1000000000000)
            {
                oreCost += sut.OreCostFor("FUEL", 1);
                if (oreCost < 1000000000000)
                {
                    fuel++;
                }
            }
            Assert.Equal(1766154, fuel);
        }
Exemple #2
0
        public void Day10Part1_TestSolution()
        {
            string[] map = DayDataUtilities.ReadLinesFromFile("day10.txt");
            Assert.NotNull(map);
            var sut = new MonitorStation(map);

            Assert.Equal(316, sut.Asteroids.Count);
            var bestStation = sut.FindBestStation();

            Assert.Equal(26, bestStation.X);
            Assert.Equal(28, bestStation.Y);
            Assert.Equal(267, bestStation.Steps0);
        }
Exemple #3
0
        public void Day22Part1_TestSolutionByFollowingIndexInReverse()
        {
            string[] cmds = DayDataUtilities.ReadLinesFromFile("day22.txt");
            Assert.NotNull(cmds);
            Assert.Equal(100, cmds.Length);
            SlamShufflerIndex sut = new SlamShufflerIndex(10007, 3324);

            for (int i = cmds.Length - 1; i >= 0; i--)
            {
                sut.ShuffleCommandReverse(cmds[i]);
            }
            long actual = sut.TrackedIndex;

            Assert.Equal(2019, actual);
        }
Exemple #4
0
        public void Day01Part2_TestSolution()
        {
            string[] masses    = DayDataUtilities.ReadLinesFromFile("day01.txt");
            long     totalFuel = 0;
            long     mass;
            long     fuel;

            foreach (var smass in masses)
            {
                mass       = long.Parse(smass);
                fuel       = FuelCounterUpper.FuelFuelCalculator(mass);
                totalFuel += fuel;
            }
            Assert.Equal(5175499, totalFuel);
        }
Exemple #5
0
        public void Day22Part1_TestSolutionByFollowingIndex()
        {
            string[] cmds = DayDataUtilities.ReadLinesFromFile("day22.txt");
            Assert.NotNull(cmds);
            Assert.Equal(100, cmds.Length);
            SlamShufflerIndex sut = new SlamShufflerIndex(10007, 2019);

            foreach (string cmd in cmds)
            {
                sut.ShuffleCommand(cmd);
            }

            long actual = sut.TrackedIndex;

            Assert.Equal(3324, actual);
        }
Exemple #6
0
        public void Day22Part1_TestSolution()
        {
            string[] cmds = DayDataUtilities.ReadLinesFromFile("day22.txt");
            Assert.NotNull(cmds);
            Assert.Equal(100, cmds.Length);
            SlamShuffler sut = new SlamShuffler(10007);

            foreach (string cmd in cmds)
            {
                sut.ShuffleCommand(cmd);
            }

            int actual = sut.DeckOfCards.FindIndex(c => c == 2019);

            Assert.Equal(3324, actual);
            //sut.DumpDeckOfCards(@"c:\work\cards.csv");
        }
        public void Day14Part1_TestSolution()
        {
            string[] map = DayDataUtilities.ReadLinesFromFile("day14.txt");
            Assert.NotNull(map);
            Assert.Equal(63, map.Length);

            RefineryNanoFactory sut = new RefineryNanoFactory();

            foreach (string recipe in map)
            {
                sut.ParseRecipe(recipe);
            }
            Assert.Equal(63, sut.Chemicals.Count);
            long oreCost = sut.OreCostFor("FUEL", 1);

            Assert.Equal(1065255, oreCost);
        }
Exemple #8
0
        public void Day03Part2_TestSolution()
        {
            string[] vectors = DayDataUtilities.ReadLinesFromFile("day03.txt");

            Assert.Equal(2, vectors.Length);
            List <string> cmds0 = new List <string>(vectors[0].Split(','));
            List <string> cmds1 = new List <string>(vectors[1].Split(','));

            Assert.NotNull(cmds0);
            Assert.NotNull(cmds1);

            PathCmdsToPoints pathMaker = new PathCmdsToPoints();
            List <Point>     path0     = pathMaker.ParsePath(cmds0);
            List <Point>     path1     = pathMaker.ParsePath(cmds1);

            int actualSteps = pathMaker.FindLeastStepsIntersection(path0, path1);

            Assert.Equal(37390, actualSteps);
        }
        public void Day06Part1_TestSolution()
        {
            string[] orbits = DayDataUtilities.ReadLinesFromFile("day06.txt");
            Assert.Equal(1656, orbits.Length);

            NameValueCollection orbitMap = OrbitalMapper.FillOrbitMap(orbits);

            OrbitalMapper.PrintKeysAndValues(orbitMap);
            int totalOrbits = 0;
            int orbitsNow   = 0;

            foreach (var orb in orbitMap.AllKeys)
            {
                orbitsNow    = OrbitalMapper.CountOrbits(orbitMap, orb, 0);
                totalOrbits += orbitsNow;
            }

            Assert.Equal(271151, totalOrbits);
        }
Exemple #10
0
        public void Day10Part2_TestSolution()
        {
            string[] map = DayDataUtilities.ReadLinesFromFile("day10.txt");
            Assert.NotNull(map);
            var sut         = new MonitorStation(map);
            var bestStation = new Point(26, 28);
            var dictLos     = sut.CalculateLOS(bestStation);

            Assert.Equal(256, dictLos.Count);

            var polarPts = sut.MakeMapPolar(bestStation);

            // Start point is angle -1,5707963267948966, ie. -pi/2, wrap angle by adding 2 pi
            foreach (var pt in polarPts)
            {
                if (pt.angle < -1.5707963267948966)
                {
                    pt.angle += 2 * Math.PI;
                }
            }

            Assert.Equal(sut.Asteroids.Count - 1, polarPts.Count);
            SortedDictionary <double, List <PolarPoint> > dictPolar = sut.MakePolarLOS(polarPts);

            sut.DumpPolarLOS(dictPolar);
            Assert.Equal(267, dictPolar.Count);
            int        count   = 1;
            PolarPoint rock200 = null;

            foreach (var angle in dictPolar.Keys)
            {
                if (count == 200)
                {
                    rock200 = dictPolar[angle].Find(r => r.dist == dictPolar[angle].Min(p => p.dist));
                    break;
                }
                count++;
            }
            Assert.NotNull(rock200);
            Assert.Equal(1309, rock200.cartPt.Y + rock200.cartPt.X * 100);
        }
Exemple #11
0
        public void Day22Part2_TestSolutionForwardOnce()
        {
            // both are primes, 99% sure.
            long deckSize     = 119315717514047;
            long shuffleTimes = 101741582076661;

            string[] cmds = DayDataUtilities.ReadLinesFromFile("day22.txt");
            Assert.NotNull(cmds);
            Assert.Equal(100, cmds.Length);

            SlamShufflerIndex sut = new SlamShufflerIndex(deckSize, 2020);

            foreach (var cmd in cmds)
            {
                sut.ShuffleCommand(cmd);
            }

            long actual = sut.TrackedIndex;

            Assert.Equal(113106724260569, actual);
        }
Exemple #12
0
        public void Day22Part2_TestSolutionJustOnce()
        {
            // both are primes, 99% sure.
            long deckSize     = 119315717514047;
            long shuffleTimes = 101741582076661;

            string[] cmds = DayDataUtilities.ReadLinesFromFile("day22.txt");
            Assert.NotNull(cmds);
            Assert.Equal(100, cmds.Length);

            SlamShufflerIndex sut = new SlamShufflerIndex(deckSize, 2020);

            for (int i = cmds.Length - 1; i >= 0; i--)
            {
                sut.ShuffleCommandReverse(cmds[i]);
            }

            long actual = sut.TrackedIndex;

            Assert.Equal(27321782275977, actual);
        }
        public void Day06Part2_TestSolution()
        {
            string[] orbits = DayDataUtilities.ReadLinesFromFile("day06.txt");
            Assert.Equal(1656, orbits.Length);

            NameValueCollection orbitMap = OrbitalMapper.FillOrbitMap(orbits);

            Assert.Equal(1657, orbitMap.Count);

            List <string> youOrbits = new List <string>();

            youOrbits = OrbitalMapper.GetOrbits(orbitMap, "YOU", youOrbits);
            List <string> santaOrbits = new List <string>();

            santaOrbits = OrbitalMapper.GetOrbits(orbitMap, "SAN", santaOrbits);
            var notInSanta  = santaOrbits.Except(youOrbits).ToList();
            var notInYou    = youOrbits.Except(santaOrbits).ToList();
            int totalOrbits = notInSanta.Count + notInYou.Count;

            Assert.Equal(388, totalOrbits);
        }