Example #1
0
        protected override Day6InputModel CreateModel(string[] lines)
        {
            var yesQuestionsPerPerson     = new Dictionary <int, IDictionary <char, bool> >();
            var totalYesQuestionsPerGroup = new Dictionary <char, bool>();

            for (char character = 'a'; character <= 'z'; character++)
            {
                totalYesQuestionsPerGroup.Add(character, false);
            }

            for (var index = 0; index < lines.Length; index++)
            {
                var yesQuestionsPerCharacterDict = Day6Helper.GetYesQuestionsPerCharacter(lines[index]);
                yesQuestionsPerPerson.Add(index, yesQuestionsPerCharacterDict);

                foreach (var(key, value) in yesQuestionsPerCharacterDict)
                {
                    if (totalYesQuestionsPerGroup.ContainsKey(key))
                    {
                        totalYesQuestionsPerGroup[key] = totalYesQuestionsPerGroup[key] ||
                                                         yesQuestionsPerCharacterDict[key];
                    }
                }
            }

            return(new Day6InputModel(yesQuestionsPerPerson, totalYesQuestionsPerGroup));
        }
Example #2
0
        protected override Day6InputModel CreateModel(string[] inputLines)
        {
            var yesQuestionsPerPerson     = new Dictionary <int, IDictionary <char, bool> >();
            var totalYesQuestionsPerGroup = new Dictionary <char, bool>();

            var firstPersonYesQuestions = Day6Helper.GetYesQuestionsPerCharacter(inputLines[0]);

            totalYesQuestionsPerGroup = firstPersonYesQuestions;
            yesQuestionsPerPerson.Add(0, firstPersonYesQuestions);

            for (var index = 1; index < inputLines.Length; index++)
            {
                var yesQuestionsPerCharacterDict = Day6Helper.GetYesQuestionsPerCharacter(inputLines[index]);
                yesQuestionsPerPerson.Add(index, yesQuestionsPerCharacterDict);

                foreach (var(key, value) in yesQuestionsPerCharacterDict)
                {
                    totalYesQuestionsPerGroup[key] = totalYesQuestionsPerGroup[key] &&
                                                     yesQuestionsPerCharacterDict[key];
                }
            }

            return(new Day6InputModel(yesQuestionsPerPerson, totalYesQuestionsPerGroup));
        }