예제 #1
0
        public long RunSecond()
        {
            var allLines = IChallenge.GetAllLines("6_1.txt");

            //var allLines= IChallenge.GetAllLines("test_6_1.txt");
            return(GetSharedAnswers(allLines));
        }
예제 #2
0
        public long RunFirst()
        {
            //var allLines = IChallenge.GetAllLines("test_9.txt");
            var allLines = IChallenge.GetAllLines("9_1.txt");
            var first    = FindFirstInvalidXMAS(allLines.Select(long.Parse).ToArray(), 25);

            return(long.Parse(allLines[first]));
        }
예제 #3
0
        public long RunFirst()
        {
            _instructions = IChallenge.GetAllLines("8_1.txt");
            //_instructions = IChallenge.GetAllLines("test_8_1.txt");

            DoInstruction(0);
            return(_accumulator);
        }
예제 #4
0
        public long RunFirst()
        {
            //var allLines= IChallenge.GetAllLines("test_6_1.txt");
            var allLines     = IChallenge.GetAllLines("6_1.txt");
            var totalAnswers = GetDistinctAnswers(allLines);

            return(totalAnswers);
        }
예제 #5
0
        public long RunSecond()
        {
            var dictionaryRatingsPathsToZero = new Dictionary <long, long>();

            var ratings = IChallenge.GetAllLines("10_1.txt").Select(long.Parse).ToList();

            ratings.Add(0);
            ratings.Sort();
            var endRating = ratings[^ 1] + 3;
예제 #6
0
        public long RunSecond()
        {
            //var allLines = IChallenge.GetAllLines("test_simple_7_2.txt");
            //var allLines = IChallenge.GetAllLines("test_7_2.txt");
            var allLines = IChallenge.GetAllLines("7_1.txt");
            var contents = GetDictionaryOfContents(allLines);
            var bagCount = TraverseBags("shiny gold", contents) - 1; // do not count the shiny bag in it self

            return(bagCount);
        }
예제 #7
0
        public long RunFirst()
        {
            //var allLines = IChallenge.GetAllLines("test_7_1.txt");
            var allLines            = IChallenge.GetAllLines("7_1.txt");
            var containerDictionary = GetDictionaryOfContainers(allLines);

            containerDictionary.TryGetValue("shiny gold", out var containers);
            var allNodes = TraverseContainers(containers, containerDictionary);

            return(allNodes.Count);
        }
예제 #8
0
        public long RunFirst()
        {
            var allLines = IChallenge.GetAllLines("5_1.txt");

            /*var maxSeatId = long.MinValue;
             * foreach (var line in allLines)
             * {
             *  var seatId = ParseSeatId(line);
             *  maxSeatId = seatId > maxSeatId ? seatId : maxSeatId;
             * }
             * return maxSeatId;*/

            //return allLines.Select(line => ParseSeatId(line)).Max();

            return(allLines.Select(ParseSeatId).Max());
        }
예제 #9
0
        public long RunSecond()
        {
            //var allLines = IChallenge.GetAllLines("test_9.txt").Select(long.Parse).ToArray();
            //var first = FindFirstInvalidXMAS(allLines, 5);

            var allLines = IChallenge.GetAllLines("9_1.txt").Select(long.Parse).ToArray();
            var first    = FindFirstInvalidXMAS(allLines, 25);

            var value = allLines[first];

            var tuple   = FindContignuousSequence(allLines, value);
            var segment = allLines.Skip(tuple.i).Take(tuple.j - tuple.i + 1).ToArray();

            //var segment = new ArraySegment<long>(allLines, tuple.i, tuple.j-1).ToArray();
            Array.Sort(segment);

            return(segment[0] + segment[^ 1]);
예제 #10
0
        public long RunSecond()
        {
            var allLines = IChallenge.GetAllLines("5_1.txt");
            var seatIds  = allLines.Select(ParseSeatId).OrderBy(id => id).ToList();

            long mySeatId = 0;

            for (var i = 0; i < seatIds.Count; i++)
            {
                if (seatIds[i + 1] > seatIds[i] + 1)
                {
                    mySeatId = seatIds[i] + 1;
                    break;
                }
            }

            return(mySeatId);
        }
예제 #11
0
        private static IEnumerable <string> GetValidPassports()
        {
            var file = "4_1.txt";
            //var file = "test_4_1.txt";
            //var file = "test_4_2_invalid.txt";
            //var file = "test_4_2_valid.txt";
            var _allLines = IChallenge.GetAllLines(file);
            var passPorts = new List <string>();

            var passportBuilder = new StringBuilder();

            foreach (var line in _allLines)
            {
                if (!string.IsNullOrEmpty(line) && !string.IsNullOrWhiteSpace(line))
                {
                    if (passportBuilder.Length > 0)
                    {
                        passportBuilder.Append(' ');
                    }

                    passportBuilder.Append(line);
                }
                else
                {
                    passPorts.Add(passportBuilder.ToString());
                    passportBuilder.Clear();
                }
            }

            //add dangling line from StringBuilder, because the was no blank line at the end of the file.
            passPorts.Add(passportBuilder.ToString());

            var validPassports = passPorts.Where(p =>
            {
                var split = p.Split(' ');
                return(split.Length == 8 || (split.Length == 7 && !p.Contains("cid")));
            });

            return(validPassports);
        }
예제 #12
0
        public long RunFirst()
        {
            var ratings = IChallenge.GetAllLines("10_1.txt").Select(long.Parse).ToList();

            ratings.Add(0);
            ratings.Sort();

            long oneGabCount   = 0;
            long threeGabCount = 1;

            for (var i = 0; i < ratings.Count - 1; i++)
            {
                if (ratings[i] + 1 == ratings[i + 1])
                {
                    oneGabCount++;
                }
                if (ratings[i] + 3 == ratings[i + 1])
                {
                    threeGabCount++;
                }
            }

            return(oneGabCount * threeGabCount);
        }
예제 #13
0
        public long RunSecond()
        {
            //_instructions = IChallenge.GetAllLines("test_8_1.txt");
            _instructions = IChallenge.GetAllLines("8_1.txt");

            var nopInstrunction = "nop";
            var jmpInstruction  = "jmp";
            var jmps            = Enumerable.Range(0, _instructions.Length).Where(i => _instructions[i].Contains(jmpInstruction)).ToList();
            var nops            = Enumerable.Range(0, _instructions.Length).Where(i => _instructions[i].Contains(nopInstrunction)).ToList();

            foreach (var jmp in jmps)
            {
                _set.Clear();
                _accumulator       = 0;
                _instructions[jmp] = _instructions[jmp].Replace(jmpInstruction, nopInstrunction);
                if (DoInstruction(0) == 0)
                {
                    return(_accumulator);
                }
                _instructions[jmp] = _instructions[jmp].Replace(nopInstrunction, jmpInstruction);
            }

            foreach (var nop in nops)
            {
                _set.Clear();
                _accumulator       = 0;
                _instructions[nop] = _instructions[nop].Replace(nopInstrunction, jmpInstruction);
                if (DoInstruction(0) == 0)
                {
                    return(_accumulator);
                }
                _instructions[nop] = _instructions[nop].Replace(jmpInstruction, nopInstrunction);
            }

            throw new Exception("Not path to end was found");
        }