Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Day 1 Solutions

            /**Console.WriteLine("Enter the Filename you would like to read from: ");
             * string filename = Console.ReadLine();
             * Console.WriteLine("Enter the desired sum you would like to calculate from: ");
             * string desiredSum = Console.ReadLine();
             * string path = ASSET_PATH + filename;
             *
             *
             * var resortRepair = new ResortRepair(path, int.Parse(desiredSum));
             *
             * var res = resortRepair.GetSolution1();
             *
             * Console.WriteLine("The sum for problem 1 is : " + res);
             *
             * res = resortRepair.GetSolution2();
             *
             * Console.WriteLine("The sum for problem 2 is : " + res);
             **/


            //Day 4 Solutions
            Console.WriteLine("Enter the Filename you would like to read from: ");
            string filename = Console.ReadLine();
            string path     = ASSET_PATH + filename;
            var    res      = PassportProcessing.GetValidPassportCount(path, false);

            Console.WriteLine("The Number of Valid Passports without validating data is: " + res);

            res = PassportProcessing.GetValidPassportCount(path, true);
            Console.WriteLine("The Number of Valid Passports with validating data is: " + res);
        }
Exemplo n.º 2
0
        public void GetKeysValuesFromPassport()
        {
            this._passportProcessing = new PassportProcessing(this._input);
            IEnumerable <Passport> passports = this._passportProcessing.GetPassports();

            int passwordValidCount = this._passportProcessing.CountValidPassport(passports);

            Assert.IsTrue(passwordValidCount == 123);
        }
Exemplo n.º 3
0
        public void CountPasswordValid()
        {
            this._passportProcessing = new PassportProcessing(this._input);
            IEnumerable <string> passportsKeysValues = this._passportProcessing.GetPassportsKeysValues();

            int passwordValidCount = this._passportProcessing.CountValidPassportKeysValues(passportsKeysValues);

            Assert.IsTrue(passwordValidCount == 206);
        }
Exemplo n.º 4
0
        public void ExamplePartTwo(string[] input, int expectedValid)
        {
            // Arrange
            var scanner = new PassportProcessing(input);

            // Act
            var count = scanner.AnalysePassportsWithRules();

            // Assert
            Assert.AreEqual(expectedValid, count);
        }
Exemplo n.º 5
0
        public void Should_collect_present_passports()
        {
            var inputReaders       = new InputReaders();
            var passportProcessing = new PassportProcessing();
            var path      = @"C:\Users\emollett\Documents\sites\AdventOfCode2020\AdventOfCode2020\Inputs\04_PassportProcessing_Test.txt";
            var passports = inputReaders.readParagraphsToList(path);

            var present = passportProcessing.collectPassports(passports);

            Assert.Equal(2, present.Count);
        }
Exemplo n.º 6
0
        public void Should_not_approve_non_passport()
        {
            var inputReaders       = new InputReaders();
            var passportProcessing = new PassportProcessing();
            var path      = @"C:\Users\emollett\Documents\sites\AdventOfCode2020\AdventOfCode2020\Inputs\04_PassportProcessing_Test.txt";
            var passports = inputReaders.readParagraphsToList(path);

            var notPassport = passportProcessing.checkAPassportIsPresent(passports[1]);

            Assert.False(notPassport);
        }
Exemplo n.º 7
0
        public void Should_read_a_passport()
        {
            var inputReaders = new InputReaders();
            var path         = @"C:\Users\emollett\Documents\sites\AdventOfCode2020\AdventOfCode2020\Inputs\04_PassportProcessing_Test.txt";
            var passports    = inputReaders.readParagraphsToList(path);

            var passport = new PassportProcessing(passports[0]);

            Assert.Equal("1937", passport.byr);
            Assert.Equal("gry", passport.ecl);
        }
Exemplo n.º 8
0
        public void Should_not_pass_invalid_passports()
        {
            var inputReaders       = new InputReaders();
            var passportProcessing = new PassportProcessing();
            var path      = @"C:\Users\emollett\Documents\sites\AdventOfCode2020\AdventOfCode2020\Inputs\04_PassportProcessing_Test_invalidpassports.txt";
            var passports = inputReaders.readParagraphsToList(path);
            var present   = passportProcessing.collectPassports(passports);

            var validPassports = passportProcessing.checkIfValid(present);

            Assert.Equal(0, validPassports.Count);
        }
Exemplo n.º 9
0
        internal static async Task Main()
        {
            string[] input = await FileUtils.ReadFileContentFromPathAsync("AOC-2020-D-4-input.txt");

            PassportProcessing passportProcessing = new PassportProcessing(input);

            IEnumerable <string>   passportsKeysValues = passportProcessing.GetPassportsKeysValues();
            IEnumerable <Passport> passports           = passportProcessing.GetPassports();

            Console.WriteLine("====================================================");
            Console.WriteLine("ADVENT OF CODE 2020 - DAY 4: PASSPORT PROCESSING");
            Console.WriteLine("====================================================");
            Console.WriteLine("----- PART 1 -----");
            Console.WriteLine($"Result: {passportProcessing.CountValidPassportKeysValues(passportsKeysValues)}");
            Console.WriteLine("----- PART 2 -----");
            Console.WriteLine($"Result: {passportProcessing.CountValidPassport(passports)}");
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            // Day 1
            var    sum          = 2020;
            string day1FilePath = @"C:\Users\musomanu\source\advent-of-code-2020\2020-Day-1\ReportRepairInput.txt";

            ReportRepair reportRepair        = new ReportRepair(day1FilePath);
            var          twoEntriesProduct   = reportRepair.Find2EntriesProduct(sum);
            var          threeEntriesProduct = reportRepair.Find3EntriesProduct(sum);

            Console.WriteLine($"Day 1: Product of 2 entries that add upto {sum}: {twoEntriesProduct}");
            Console.WriteLine($"Day 1: Product of 3 entries that add upto {sum}: {threeEntriesProduct}");
            Console.WriteLine();

            // Day 2
            string day2FilePath = @"C:\Users\musomanu\source\advent-of-code-2020\2020-Day-2\PasswordPhilosophyInput.txt";

            PasswordPhilosophy passwordPhilosophy = new PasswordPhilosophy(day2FilePath);
            var numberOfValidPasswords            = passwordPhilosophy.GetValidPasswordsCount();
            var numberOfValidPasswordsRevised     = passwordPhilosophy.GetValidPasswordsCountRevised();

            Console.WriteLine($"Day 2: Number of valid passwords: {numberOfValidPasswords}");
            Console.WriteLine($"Day 2: Number of valid passwords (revised policy): {numberOfValidPasswordsRevised}");
            Console.WriteLine();

            // Day 3
            string day3FilePath = @"C:\Users\musomanu\source\advent-of-code-2020\2020-Day-3\TobogganTrajectoryInput.txt";

            TobogganTrajectory tobogganTrajectory = new TobogganTrajectory(day3FilePath);
            var numberOfTreesEncountered          = tobogganTrajectory.TreesEncountered(0, 0, 3, 1);
            var numberofTreesEncountered_1        = tobogganTrajectory.TreesEncountered(0, 0, 1, 1);
            var numberofTreesEncountered_2        = tobogganTrajectory.TreesEncountered(0, 0, 3, 1);
            var numberofTreesEncountered_3        = tobogganTrajectory.TreesEncountered(0, 0, 5, 1);
            var numberofTreesEncountered_4        = tobogganTrajectory.TreesEncountered(0, 0, 7, 1);
            var numberofTreesEncountered_5        = tobogganTrajectory.TreesEncountered(0, 0, 1, 2);
            var numberofTreesEncounteredProduct   = numberofTreesEncountered_1 * numberofTreesEncountered_2 * numberofTreesEncountered_3 * numberofTreesEncountered_4 * numberofTreesEncountered_5;

            Console.WriteLine($"Day 3: Number of trees encountered: {numberOfTreesEncountered}");
            Console.WriteLine($"Day 3: Number of trees encountered (all slopes product): {numberofTreesEncounteredProduct}");
            Console.WriteLine();

            // Day 4
            string day4FilePath = @"C:\Users\musomanu\source\advent-of-code-2020\2020-Day-4\PassportProcessingInput.txt";

            PassportProcessing passportProcessing = new PassportProcessing(day4FilePath);
            var numberOfValidPassports            = passportProcessing.GetValidPassportsCount();
            var numberOfValidPassportsRevised     = passportProcessing.GetValidPassportsCountRevised();

            Console.WriteLine($"Day 4: Number of valid passports: {numberOfValidPassports}");
            Console.WriteLine($"Day 4: Number of valid passports (revised validation): {numberOfValidPassportsRevised}");
            Console.WriteLine();

            // Day 5
            string day5FilePath = @"C:\Users\musomanu\source\advent-of-code-2020\2020-Day-5\BinaryBoardingInput.txt";

            BinaryBoarding binaryBoarding = new BinaryBoarding(day5FilePath);
            var            highestSeatId  = binaryBoarding.GetHighestSeatId();
            var            mySeatId       = binaryBoarding.GetMySeatId();

            Console.WriteLine($"Day 5: Highest seat id: {highestSeatId}");
            Console.WriteLine($"Day 5: My seat id: {mySeatId}");
            Console.WriteLine();
        }