public void CountValidPasswordWithExampleOfPartTwo()
        {
            string[] passwords           = new[] { "1-3 a: abcde", "1-3 b: cdefg", "2-9 c: ccccccccc" };
            int      validPasswordsCount = PasswordPhilosophy.GetNumbersValidPasswordsContainsExactlyOccurrenceCharacter(passwords);

            Assert.IsTrue(validPasswordsCount == 1);
        }
Example #2
0
        internal static async Task Main(string[] args)
        {
            string[] passwords = await FileUtils.ReadFileContentFromPathAsync("AOC-2020-D-2-input.txt");

            int countValidPasswordPartOne = 0;

            if (passwords != null && passwords.Length > 0)
            {
                countValidPasswordPartOne = PasswordPhilosophy.GetNumbersValidPasswordsContainsOccurrenceCharacter(passwords);
            }
            int countValidPasswordPartTwo = 0;

            if (passwords != null && passwords.Length > 0)
            {
                countValidPasswordPartTwo = PasswordPhilosophy.GetNumbersValidPasswordsContainsExactlyOccurrenceCharacter(passwords);
            }

            Console.WriteLine("====================================================");
            Console.WriteLine("ADVENT OF CODE 2020 - DAY 2: PASSWORD PHILOSOPHY");
            Console.WriteLine("====================================================");
            Console.WriteLine("----- PART 1 -----");
            Console.WriteLine($"Result: {countValidPasswordPartOne}");
            Console.WriteLine("----- PART 2 -----");
            Console.WriteLine($"Result: {countValidPasswordPartTwo}");
        }
Example #3
0
        public void ExamplePartTwo(string[] input, int expectedValid)
        {
            // Arrange
            var passwordPhilosphy = new PasswordPhilosophy(input);

            // Act
            var output = passwordPhilosphy.PartTwo();

            // Assert
            Assert.AreEqual(expectedValid, output);
        }
Example #4
0
        public void Day02_PartOneTest()
        {
            var lines = new[]
            {
                "1-3 a: abcde",
                "1-3 b: cdefg",
                "2-9 c: ccccccccc"
            };

            Assert.AreEqual(2, PasswordPhilosophy.GetValidPasswords(lines.Select(PasswordPolicy.Parse).ToList(), PasswordPhilosophy.RentalPlace.Sleds).Length);
        }
Example #5
0
        public void PuzzlePartTwo()
        {
            //  Arrange
            var input = File
                        .ReadLines("tests/y2020/Day2.Input.txt")
                        .ToList();

            // Act
            var actual = PasswordPhilosophy.AreValidOccurence(input);

            // Assert
            Assert.Equal(562, actual);
        }
Example #6
0
        public void PuzzlePartOne()
        {
            //  Arrange
            var input = File
                        .ReadLines("tests/y2020/Day2.Input.txt")
                        .ToList();

            // Act
            var actual = PasswordPhilosophy.AreValidCount(input);

            // Assert
            Assert.Equal(398, actual);
        }
Example #7
0
        public void PuzzleTwo()
        {
            var input = new string[] {
                "1-3 b: cdefg",
                "1-3 a: abcde",
                "2-9 c: ccccccccc"
            };

            // Act
            var actual = PasswordPhilosophy.AreValidOccurence(input);

            // Assert
            Assert.Equal(1, actual);
        }
Example #8
0
        public void PuzzleOne()
        {
            // Arrange
            var input = new string[] {
                "1-3 b: cdefg",
                "1-3 a: abcde",
                "2-9 c: ccccccccc"
            };

            // Act
            var actual = PasswordPhilosophy.AreValidCount(input);

            // Assert
            Assert.Equal(2, actual);
        }
Example #9
0
 public void Day02_PartTwoTest()
 {
     Assert.AreEqual(688, PasswordPhilosophy.GetValidPasswords(_input, PasswordPhilosophy.RentalPlace.Tobogan).Length);
 }
Example #10
0
 public void Day02_PartOneTest()
 {
     Assert.AreEqual(416, PasswordPhilosophy.GetValidPasswords(_input, PasswordPhilosophy.RentalPlace.Sleds).Length);
 }
Example #11
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();
        }
 private void SetPasswordTestProperties(string passwordsWithPolicy)
 {
     this._passwordPolicy  = PasswordPhilosophy.GetPasswordPolicy(passwordsWithPolicy);
     this._password        = PasswordPhilosophy.GetPassword(passwordsWithPolicy);
     this._passwordIsValid = PasswordPhilosophy.PasswordContainsOneOrMoreOccurrenceCharacterReferenceIsValid(this._passwordPolicy, this._password);
 }