Example #1
0
        public void ShouldCountPlanOverlapFromBigInput()
        {
            var plans  = PuzzleInputParser.ParseStrings("Day3/Input.txt");
            var fabric = new PrototypeFabric(1000, plans);

            fabric.CountAreaOfOverlaps().Should().Be(116491);
        }
Example #2
0
        public void ShouldFindFirstNonOverlappingPlanFromBigInput()
        {
            var plans  = PuzzleInputParser.ParseStrings("Day3/Input.txt");
            var fabric = new PrototypeFabric(1000, plans);

            fabric.GetFirstNonOverlappingPlanId().Should().Be("707");
        }
Example #3
0
        public static IEnumerable <object[]> GetDay8Data()
        {
            yield return(new object[]
            {
                new List <RegisterInstruction>
                {
                    new RegisterInstruction("b inc 5 if a > 1"),
                    new RegisterInstruction("a inc 1 if b < 5"),
                    new RegisterInstruction("c dec -10 if a >= 1"),
                    new RegisterInstruction("c inc -20 if c == 10")
                },
                1,
                10
            });

            var input = PuzzleInputParser.Parse("Day8Input.txt");
            var lines = input
                        .Split(new[] { "\r\n" }, StringSplitOptions.None)
                        .ToList();

            yield return(new object[]
            {
                lines.Select(l => new RegisterInstruction(l)),
                3745,
                4644
            });
        }
        public int DoPartOne(string fileLocation)
        {
            var input = PuzzleInputParser.GetString(fileLocation);

            AddOrbits(input);
            return(FindOrbitCount());
        }
        public async Task ShouldPerformOptimizedPolymerReactionForBigInput()
        {
            var sut = new OptimizedPolymer(PuzzleInputParser.ParseString("Day5/Input.txt"));
            await sut.ReactAsync();

            sut.Units.Should().Be(5122);
        }
Example #6
0
        public void ShouldCalculateRootNodeValueFromBigInput()
        {
            var raw = PuzzleInputParser.ParseString("Day8/Input.txt");
            var sut = new Tree(raw);

            sut.RootNodeValue.Should().Be(28779);
        }
Example #7
0
        public void ShouldCalculateMetadataSumFromBigInput()
        {
            var raw = PuzzleInputParser.ParseString("Day8/Input.txt");
            var sut = new Tree(raw);

            sut.MetadataSum.Should().Be(40309);
        }
        public void ShouldFindCrashLocationFromBigInput()
        {
            var sut   = new CartTracks(PuzzleInputParser.ParseStrings("Day13/BigInput.txt"));
            var crash = sut.MoveCartsUntilCrash();

            crash.X.Should().Be(76);
            crash.Y.Should().Be(108);
        }
        public void ShouldFindLastCarThatHasntCrashed()
        {
            var sut  = new CartTracks(PuzzleInputParser.ParseStrings("Day13/BigInput.txt"));
            var cart = sut.MoveCartsUntilAllButOneHaveCrashed();

            cart.CurrentTrack.X.Should().Be(2);
            cart.CurrentTrack.Y.Should().Be(84);
        }
        public void ShouldFindCrashLocationFromSmallExample()
        {
            var sut   = new CartTracks(PuzzleInputParser.ParseStrings("Day13/SmallInput.txt"));
            var crash = sut.MoveCartsUntilCrash();

            crash.X.Should().Be(7);
            crash.Y.Should().Be(3);
        }
Example #11
0
        public void ShouldCalculateRegionClosestToMostCoordinatesFromBigInput()
        {
            var sut = new CoordinateGrid(PuzzleInputParser.ParseStrings("Day6/Input.txt"), 10000);

            sut.CalculateManhattanDistancesForGrid();

            sut.RegionClosestToMostCoordinates.Should().Be(37093);
        }
Example #12
0
        public void ShouldCalculateCoordinateFurthestFromOtherCoordinatesFromBigInput()
        {
            var sut = new CoordinateGrid(PuzzleInputParser.ParseStrings("Day6/Input.txt"), 10000);

            sut.CalculateManhattanDistancesForGrid();

            sut.CoordinateFurthestFromOtherCoordinates.Area.Should().Be(5358);
        }
Example #13
0
        public CrossedWires(string filePath)
        {
            var data = PuzzleInputParser.GetString(filePath);

            var rows      = data.Split("\n");
            var firstRow  = rows[0];
            var secondRow = rows[1];

            First  = firstRow.Split(",");
            Second = secondRow.Split(",");
        }
Example #14
0
        public void ShouldFindGuardMostFrequentlyAsleepAtSameMinuteFromBigInput()
        {
            var shiftLogs = PuzzleInputParser.ParseStrings("Day4/Input.txt");
            var sut       = new GuardShiftTracker(shiftLogs);

            var guard = sut.FindGuardMostFrequentlyAsleepAtSameMinute();

            guard.Id.Should().Be(269);
            guard.MinuteAsleepMost.Should().Be(39);
            (guard.Id * guard.MinuteAsleepMost).Should().Be(10491);
        }
Example #15
0
        public void ShouldFindSleepiestGuardFromBigInput()
        {
            var shiftLogs = PuzzleInputParser.ParseStrings("Day4/Input.txt");
            var sut       = new GuardShiftTracker(shiftLogs);

            var guard = sut.FindGuardWithMostMinutesAsleep();

            guard.Id.Should().Be(3557);
            guard.MinuteAsleepMost.Should().Be(30);
            (guard.Id * guard.MinuteAsleepMost).Should().Be(106710);
        }
Example #16
0
        public void ShouldPrintPossibleTextForBigInput()
        {
            var points = PointOfLightParser.Parse(PuzzleInputParser.ParseStrings("Day10/Input.txt")).ToList();

            var sut = new Sky(points);

            sut.MoveTimeUntilStarsSpellMessage();
            sut.Print();

            PuzzleInputParser.ParseString("Day10/Output.txt").Should().Be(PuzzleInputParser.ParseString("Day10/BigOutput.txt"));
            sut.Seconds.Should().Be(10681);
        }
        public void should_count_wooden_areas_and_lumberyards_in_big_input()
        {
            var sut = new LumberArea(PuzzleInputParser.ParseStrings("Day18/Input.txt"));

            sut.PassMinutes(10);

            var forestCount     = sut.CountAllWoodedAreas();
            var lumberyardCount = sut.CountAllLumberyards();

            forestCount.Should().Be(709);
            lumberyardCount.Should().Be(502);

            (forestCount * lumberyardCount).Should().Be(355918);
        }
Example #18
0
        public void ShouldPrintPossibleTextForExampleInput()
        {
            var points = PointOfLightParser.Parse(new List <string>
            {
                "position=< 9,  1> velocity=< 0,  2>",
                "position=< 7,  0> velocity=<-1,  0>",
                "position=< 3, -2> velocity=<-1,  1>",
                "position=< 6, 10> velocity=<-2, -1>",
                "position=< 2, -4> velocity=< 2,  2>",
                "position=<-6, 10> velocity=< 2, -2>",
                "position=< 1,  8> velocity=< 1, -1>",
                "position=< 1,  7> velocity=< 1,  0>",
                "position=<-3, 11> velocity=< 1, -2>",
                "position=< 7,  6> velocity=<-1, -1>",
                "position=<-2,  3> velocity=< 1,  0>",
                "position=<-4,  3> velocity=< 2,  0>",
                "position=<10, -3> velocity=<-1,  1>",
                "position=< 5, 11> velocity=< 1, -2>",
                "position=< 4,  7> velocity=< 0, -1>",
                "position=< 8, -2> velocity=< 0,  1>",
                "position=<15,  0> velocity=<-2,  0>",
                "position=< 1,  6> velocity=< 1,  0>",
                "position=< 8,  9> velocity=< 0, -1>",
                "position=< 3,  3> velocity=<-1,  1>",
                "position=< 0,  5> velocity=< 0, -1>",
                "position=<-2,  2> velocity=< 2,  0>",
                "position=< 5, -2> velocity=< 1,  2>",
                "position=< 1,  4> velocity=< 2,  1>",
                "position=<-2,  7> velocity=< 2, -2>",
                "position=< 3,  6> velocity=<-1, -1>",
                "position=< 5,  0> velocity=< 1,  0>",
                "position=<-6,  0> velocity=< 2,  0>",
                "position=< 5,  9> velocity=< 1, -2>",
                "position=<14,  7> velocity=<-2,  0>",
                "position=<-3,  6> velocity=< 2, -1>",
            }).ToList();

            var sut = new Sky(points);

            sut.MoveTimeUntilStarsSpellMessage();
            sut.Print();

            PuzzleInputParser.ParseString("Day10/Output.txt").Should().Be(PuzzleInputParser.ParseString("Day10/ExampleOutput.txt"));
            sut.Seconds.Should().Be(3);
        }
Example #19
0
        public int DoPartTwo()
        {
            for (var noun = 0; noun <= 99; noun++)
            {
                for (var verb = 0; verb <= 99; verb++)
                {
                    Codes = PuzzleInputParser.CSVNumbersToList(fileLocation); // brilliantly inefficient
                    RestoreGravity(noun, verb);

                    var number = StartComputer();

                    if (number == 19690720)
                    {
                        return(noun * 100 + verb);
                    }
                }
            }
            return(0);
        }
Example #20
0
 public FuelCalculator(string fileLocation)
 {
     masses = PuzzleInputParser.RowsOfNumbersToList(fileLocation);
 }
 public void TestParseListOfNumbers()
 {
     Assert.AreEqual(100, PuzzleInputParser.RowsOfNumbersToList("DayOne/Data.txt").Count);
 }
        public void should_observe_change_pattern_over_many_minutes()
        {
            var sut = new LumberArea(PuzzleInputParser.ParseStrings("Day18/Input.txt"));

            var minute = 0;

            var forestCount     = sut.CountAllWoodedAreas();
            var lumberyardCount = sut.CountAllLumberyards();

            while (minute < 1000)
            {
                sut.PassMinute();
                minute++;

                forestCount     = sut.CountAllWoodedAreas();
                lumberyardCount = sut.CountAllLumberyards();

                _output.WriteLine($"Minute {minute} - {forestCount}");
                _output.WriteLine($"Minute {minute} - {lumberyardCount}");
            }

            // At minute 506, this starts to repeat for the forest counts
            // Minute 506 - 586
            // Minute 507 - 580
            // Minute 508 - 573
            // Minute 509 - 572
            // Minute 510 - 568
            // Minute 511 - 568
            // Minute 512 - 567
            // Minute 513 - 570
            // Minute 514 - 570
            // Minute 515 - 573
            // Minute 516 - 572
            // Minute 517 - 575
            // Minute 518 - 573
            // Minute 519 - 576
            // Minute 520 - 576
            // Minute 521 - 581
            // Minute 522 - 586
            // Minute 523 - 591
            // Minute 524 - 593
            // Minute 525 - 600
            // Minute 526 - 602
            // Minute 527 - 603
            // Minute 528 - 606
            // Minute 529 - 609
            // Minute 530 - 606
            // Minute 531 - 606
            // Minute 532 - 601
            // Minute 533 - 596

            // and this for the lumber counts
            // Minute 506 - 358
            // Minute 507 - 358
            // Minute 508 - 351
            // Minute 509 - 344
            // Minute 510 - 339
            // Minute 511 - 337
            // Minute 512 - 332
            // Minute 513 - 331
            // Minute 514 - 329
            // Minute 515 - 331
            // Minute 516 - 332
            // Minute 517 - 335
            // Minute 518 - 337
            // Minute 519 - 336
            // Minute 520 - 338
            // Minute 521 - 337
            // Minute 522 - 338
            // Minute 523 - 339
            // Minute 524 - 342
            // Minute 525 - 341
            // Minute 526 - 346
            // Minute 527 - 350
            // Minute 528 - 354
            // Minute 529 - 353
            // Minute 530 - 354
            // Minute 531 - 355
            // Minute 532 - 357
            // Minute 533 - 360

            var forestPatternStartingAt506 = new int[]
            {
                586,
                580,
                573,
                572,
                568,
                568,
                567,
                570,
                570,
                573,
                572,
                575,
                573,
                576,
                576,
                581,
                586,
                591,
                593,
                600,
                602,
                603,
                606,
                609,
                606,
                606,
                601,
                596,
            };

            var lumberyardPatternStartingAt506 = new int[]
            {
                358,
                358,
                351,
                344,
                339,
                337,
                332,
                331,
                329,
                331,
                332,
                335,
                337,
                336,
                338,
                337,
                338,
                339,
                342,
                341,
                346,
                350,
                354,
                353,
                354,
                355,
                357,
                360
            };

            // Figure out formula, verify it works
            forestPatternStartingAt506[(1000 - 506) % forestPatternStartingAt506.Length]
            .Should()
            .Be(forestCount);

            lumberyardPatternStartingAt506[(1000 - 506) % lumberyardPatternStartingAt506.Length]
            .Should()
            .Be(lumberyardCount);
        }
Example #23
0
 public BoxChecksumTests()
 {
     _sut   = new BoxWarehouse();
     _input = PuzzleInputParser.ParseStrings("Day2/Input.txt").ToList();
 }
Example #24
0
        public static IEnumerable <object[]> GetDay7Data()
        {
            yield return(new object[]
            {
                new List <Day7_RecursiveCircus.Program>
                {
                    new Day7_RecursiveCircus.Program {
                        Name = "pbga", MyWeight = 66, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "xhth", MyWeight = 57, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "ebii", MyWeight = 61, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "havc", MyWeight = 66, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "ktlj", MyWeight = 57, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "fwft", MyWeight = 72, ProgramNamesOnDisc = new List <string> {
                            "ktlj", "cntj", "xhth"
                        }
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "qoyq", MyWeight = 66, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "padx", MyWeight = 45, ProgramNamesOnDisc = new List <string> {
                            "pbga", "havc", "qoyq"
                        }
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "tknk", MyWeight = 41, ProgramNamesOnDisc = new List <string> {
                            "ugml", "padx", "fwft"
                        }
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "jptl", MyWeight = 61, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "ugml", MyWeight = 68, ProgramNamesOnDisc = new List <string> {
                            "gyxo", "ebii", "jptl"
                        }
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "gyxo", MyWeight = 61, ProgramNamesOnDisc = new List <string>()
                    },
                    new Day7_RecursiveCircus.Program {
                        Name = "cntj", MyWeight = 57, ProgramNamesOnDisc = new List <string>()
                    },
                },
                "tknk",
                60
            });

            var input = PuzzleInputParser.Parse("Day7Input.txt");
            var lines = input.Split(new[] { "\r\n" }, StringSplitOptions.None)
                        .ToList();
            var programs = new List <Day7_RecursiveCircus.Program>();

            foreach (var line in lines)
            {
                var program = new Day7_RecursiveCircus.Program
                {
                    Name = line.Substring(0, line.IndexOf("(")).Trim()
                };
                var anyStackedOnTop = line.IndexOf("->");
                if (anyStackedOnTop != -1)
                {
                    anyStackedOnTop += 2;
                    var stackedOnTop = line.Substring(anyStackedOnTop, line.Length - anyStackedOnTop).Replace(" ", "").Split(',');
                    program.ProgramNamesOnDisc = stackedOnTop.ToList();
                }
                program.MyWeight = int.Parse(line.Split('(', ')')[1]);
                programs.Add(program);
            }

            yield return(new object[]
            {
                programs,
                "wiapj",
                1072
            });
        }
Example #25
0
 public void ShouldDetermineStepForBigInput()
 {
     _sut.GetTimeToCompleteInstructions(PuzzleInputParser.ParseStrings("Day7/Input.txt"), 60, 5).Should().Be(946);
 }
Example #26
0
 public void ShouldDetermineStepOrderForBigInput()
 {
     _sut.GetStepOrder(PuzzleInputParser.ParseStrings("Day7/Input.txt")).Should().Be("FHICMRTXYDBOAJNPWQGVZUEKLS");
 }
Example #27
0
 public IntCode(string fileLocation)
 {
     this.fileLocation = fileLocation;
     Codes             = PuzzleInputParser.CSVNumbersToList(fileLocation);
 }
 public FrequencyCalibrationTests()
 {
     _sut   = new FrequencyCalibration();
     _input = PuzzleInputParser.ParseInts("Day1/Input.txt");
 }
 public void TestCalculateFuelRequiredForPartTwo()
 {
     Assert.AreEqual(165, PuzzleInputParser.CSVNumbersToList("DayTwo/Data.txt").Count);
 }