コード例 #1
0
        public void Ex1()
        {
            var lines               = FileReaderHelper.GetLines("input06.txt");
            var groupCount          = new Dictionary <int, int>();
            var currentGroupAnswers = string.Empty;
            int index               = 0;

            foreach (var line in lines)
            {
                if (line == string.Empty)
                {
                    var answers = currentGroupAnswers.ToCharArray().Distinct().Count();
                    groupCount.Add(index, answers);
                    currentGroupAnswers = string.Empty;
                    index++;
                }
                currentGroupAnswers += line;
            }
            var last = currentGroupAnswers.ToCharArray().Distinct().Count();

            groupCount.Add(index, last);
            var sum = 0;

            foreach (var item in groupCount.Values)
            {
                sum += item;
            }
            Console.WriteLine($"aantal: {sum}");
            Console.ReadLine();
        }
コード例 #2
0
        public void Ex2()
        {
            var   lines      = FileReaderHelper.GetLines("input06.txt");
            var   groupCount = new List <int>();
            Group group      = new Group();

            foreach (var line in lines)
            {
                if (line == string.Empty)
                {
                    groupCount.Add(GetIntersectingAnswers(group));
                    group = new Group();
                }
                else
                {
                    group.Members.Add(new GroupMember(line));
                }
            }
            groupCount.Add(GetIntersectingAnswers(group));
            var sum = 0;

            foreach (var item in groupCount)
            {
                sum += item;
            }
            Console.WriteLine($"aantal: {sum}");
            Console.ReadLine();
        }
コード例 #3
0
        public void Ex02()
        {
            int count = 0;
            var lines = FileReaderHelper.GetLines("input02.txt");

            foreach (var line in lines)
            {
                // 13-16 k: kkkkkgmkbvkkrskhd
                var parts       = line.Split(" ");
                var startNumber = Convert.ToInt32(parts[0].Split("-")[0].Trim());                     //13
                var endNumber   = Convert.ToInt32(parts[0].Split("-")[1]);                            //16
                var letter      = Convert.ToChar(parts[1].Trim().Remove(parts[1].Trim().Length - 1)); //k
                var password    = parts[2].Trim().ToCharArray();                                      //kkkkkgmkbvkkrskhd
                if (password[startNumber - 1] == letter && password[endNumber - 1] != letter)
                {
                    Console.WriteLine(line);
                    count++;
                }
                if (password[startNumber - 1] != letter && password[endNumber - 1] == letter)
                {
                    Console.WriteLine(line);
                    count++;
                }
                //if (startNumber <= freq && freq <= endNumber)
                //{
                //    Console.WriteLine(line);
                //    count++;
                //}
            }
            Console.WriteLine($"aantal regels: {lines.Count}, aantal juiste wachtwoorden: {count}.");
            Console.ReadLine();
        }
コード例 #4
0
        public void Ex02()
        {
            int a;
            int b;
            int c;
            var lines = FileReaderHelper.GetLines("input01.txt");

            foreach (var line in lines)
            {
                a = Convert.ToInt32(line);
                foreach (var line2 in lines)
                {
                    b = Convert.ToInt32(line2);

                    foreach (var line3 in lines)
                    {
                        c = Convert.ToInt32(line3);
                        if (a + b + c == 2020)
                        {
                            Console.WriteLine($"a = {a} en b = {b} en c = {c}. a x b x c = {a * b * c}");
                        }
                    }
                }
            }
            Console.ReadLine();
        }
コード例 #5
0
        public void Ex01()
        {
            var countPassport = 0;
            var countValid    = 0;
            var countInvalid  = 0;
            var lines         = FileReaderHelper.GetLines("input04.txt");
            var passportData  = string.Empty;

            foreach (var line in lines)
            {
                if (line == string.Empty)
                {
                    var passport = new Passport(passportData.Trim());
                    countPassport++;
                    if (passport.IsValid())
                    {
                        // Console.WriteLine($"valid: {passportData}");
                        countValid++;
                    }
                    else
                    {
                        countInvalid++;
                        //Console.WriteLine($"INvalid: {passportData}");
                    }

                    passportData = string.Empty;
                    continue;
                }
                passportData = passportData + " " + line;
            }
            var lastPassport = new Passport(passportData.Trim());

            countPassport++;
            if (lastPassport.IsValid())
            {
                // Console.WriteLine($"valid: {passportData}");
                countValid++;
            }
            else
            {
                countInvalid++;
                //Console.WriteLine($"INvalid: {passportData}");
            }
            Console.WriteLine($"aantal paspoorten: {countPassport} valide aantal: {countValid} invalide aantal: {countInvalid}");
            Console.ReadLine();
        }
コード例 #6
0
        public void Ex01()
        {
            var        lines         = FileReaderHelper.GetLines("input05.txt");
            var        highestSeatId = 0;
            List <int> seatList      = new List <int>();

            foreach (var line in lines)
            {
                var row        = line.Remove(7).ToCharArray().ToList();
                var seat       = line.Remove(0, 7).ToCharArray().ToList();
                int start      = 0;
                int end        = 127;
                var rowNumber  = GetRowNumber(start, end, row);
                var seatStart  = 0;
                var seatEnd    = 7;
                var seatNumber = GetSeatNumber(seatStart, seatEnd, seat);
                var result     = (rowNumber * 8) + seatNumber;
                if (result > highestSeatId)
                {
                    highestSeatId = result;
                }
                seatList.Add(result);
            }
            var orderedList = seatList.OrderBy(x => x);
            var missinglist = new List <int>();

            foreach (var item in orderedList)
            {
                if (!seatList.Contains(item + 1))
                {
                    missinglist.Add(item + 1);
                }
            }
            Console.WriteLine($"hoogste: {highestSeatId}");
            Console.ReadLine();
        }
コード例 #7
0
        public void Ex01()
        {
            int count = 0;
            var lines = FileReaderHelper.GetLines("input03.txt");
            var index = 1;

            foreach (var line in lines)
            {
                var currentLine = line;
                var l           = currentLine.Length;
                var position    = (index * 3) - 2;
                while (currentLine.Length <= position)
                {
                    currentLine = currentLine + line;
                }
                if (currentLine.ToCharArray()[position - 1] == '#')
                {
                    count++;
                }
                index++;
            }
            Console.WriteLine($" rechts 3 down 1 geeft aantal: {count}");
            Console.ReadLine();
            long drie = count;

            count = 0;
            lines = FileReaderHelper.GetLines("input03.txt");
            index = 1;
            foreach (var line in lines)
            {
                var currentLine = line;
                var l           = currentLine.Length;
                var position    = index;
                while (currentLine.Length <= position)
                {
                    currentLine = currentLine + line;
                }
                if (currentLine.ToCharArray()[position - 1] == '#')
                {
                    // Console.WriteLine($"line: {currentLine} ppositie: {position}");
                    count++;
                }
                index++;
            }
            Console.WriteLine($" rechts 1 down 1 geeft aantal: {count}");
            Console.ReadLine();

            long een = count;

            count = 0;
            lines = FileReaderHelper.GetLines("input03.txt");
            index = 1;
            foreach (var line in lines)
            {
                var currentLine = line;
                var l           = currentLine.Length;
                var position    = (index * 5) - 4;
                while (currentLine.Length <= position)
                {
                    currentLine = currentLine + line;
                }
                if (currentLine.ToCharArray()[position - 1] == '#')
                {
                    // Console.WriteLine($"line: {currentLine} ppositie: {position}");
                    count++;
                }
                index++;
            }
            Console.WriteLine($" rechts 5 down 1 geeft aantal: {count}");
            Console.ReadLine();
            long vijf = count;

            count = 0;
            lines = FileReaderHelper.GetLines("input03.txt");
            index = 1;
            foreach (var line in lines)
            {
                var currentLine = line;
                var l           = currentLine.Length;
                var position    = (index * 7) - 6;
                while (currentLine.Length <= position)
                {
                    currentLine = currentLine + line;
                }
                if (currentLine.ToCharArray()[position - 1] == '#')
                {
                    // Console.WriteLine($"line: {currentLine} ppositie: {position}");
                    count++;
                }
                index++;
            }
            Console.WriteLine($" rechts 7 down 1 geeft aantal: {count}");
            Console.ReadLine();
            long zeven = count;

            count = 0;
            lines = FileReaderHelper.GetLines("input03.txt");
            index = 1;
            foreach (var line in lines)
            {
                if (index % 2 == 0)
                {
                    index++;
                    continue;
                }
                var currentLine = line;
                var l           = currentLine.Length;
                var position    = (index + 1) / 2;
                while (currentLine.Length <= position)
                {
                    currentLine = currentLine + line;
                }
                if (currentLine.ToCharArray()[position - 1] == '#')
                {
                    // Console.WriteLine($"line: {currentLine} ppositie: {position}");
                    count++;
                }
                index++;
            }
            Console.WriteLine($" rechts 1 down 2 geeft aantal: {count}");
            Console.ReadLine();
            long twee = count;

            Console.WriteLine($"totaal: {een * twee * drie * vijf * zeven}");
        }