Beispiel #1
0
        public string CheckInputToGetAnswerPart1()
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl);

            Boot.TryExecute(values, out var accumulatorValue);
            return(accumulatorValue.ToString());
        }
Beispiel #2
0
        private void CheckInputToGetAnswers()
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl);

            _part1Answer = 0;
            _part2Answer = 0;
            foreach (var value in values)
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }

                if (!InputStringParser.TryParseString(value, out var password, out var checkChar, out var minValue, out var maxValue))
                {
                    throw new Exception($"A value is not in the correct format, I have not planned to deal with this: {value}");
                }

                if (PasswordPolicyChecker.CheckPassword(checkChar, minValue, maxValue, password))
                {
                    _part1Answer++;
                }

                if (PasswordPolicyChecker.CheckOfficialPassword(checkChar, minValue, maxValue, password))
                {
                    _part2Answer++;
                }
            }
        }
Beispiel #3
0
        public int CheckInputToGetAnswerPart1()
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl);

            for (var i = 0; i < values.Length - 1; i++)
            {
                var firstValue = int.Parse(values[i]);
                for (var j = i + 1; j < values.Length - 1; j++)
                {
                    var secondValue = int.Parse(values[j]);
                    if (NumberChecker.TryGetCombinedNumberIfNumbersSumTo2020(new [] { firstValue, secondValue }, out var combinedValue) && combinedValue != null)
                    {
                        return((int)combinedValue);
                    }
                }
            }

            throw new Exception("No values in the input combine to 2020");
        }
Beispiel #4
0
        private long CheckInput(int xOffset, int yOffset)
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl);

            var treeCount = 0;

            for (var startingPosition = new Point(0, 0); startingPosition.Y < values.Length - 1; startingPosition.Offset(xOffset, yOffset))
            {
                if (SlopeChecker.CheckIfPositionHoldsATree(values, startingPosition))
                {
                    treeCount++;
                }
            }

            return(treeCount);
        }
Beispiel #5
0
        private List <Seat> GetSeats()
        {
            var seats  = new List <Seat>();
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl);

            for (var i = 0; i < values.Length; i++)
            {
                var row = values[i];

                for (var j = 0; j < row.Length; j++)
                {
                    var seat = new Seat().CreateSeat(values[i][j], new Point(j, i));
                    if (seat != null)
                    {
                        seats.Add(seat);
                    }
                }
            }

            return(seats);
        }
Beispiel #6
0
        public string CheckInputToGetAnswerPart1()
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl, "\n\n");

            return(values.Count(v => new Passport(v).CheckPassportThatFieldsExist).ToString());
        }
Beispiel #7
0
        public string CheckInputToGetAnswerPart1()
        {
            var values = _puzzleInput.GetPuzzleInputAsArray(InputUrl, "\n\n");

            return(values.Select(value => value.Split("\n").SelectMany(s => s.ToCharArray())).Select(questions => questions.Distinct().Count()).Sum().ToString());
        }