From b73786aca5161be5fa46d980d799ec3d78b85727 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 3 Dec 2022 16:38:10 +0000 Subject: [PATCH] Completed 2015 day 5 --- 2015/Day-05/Day05.cs | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 2015/Day-05/Day05.cs diff --git a/2015/Day-05/Day05.cs b/2015/Day-05/Day05.cs new file mode 100644 index 0000000..6993604 --- /dev/null +++ b/2015/Day-05/Day05.cs @@ -0,0 +1,68 @@ +using System.Text.RegularExpressions; + +List vowels = new List{'a','e','i','o','u'}; +List badStrings = new List{"ab", "cd", "pq", "xy"}; +int goodStrings = 0; + +foreach(string line in File.ReadLines("input.txt")){ + int vowelsInLine = 0; + foreach(char letter in line){ + if(vowels.IndexOf(letter) != -1){ + vowelsInLine++; + } + } + if(vowelsInLine < 3){ + continue; + } + + int repeatedLetters = 0; + for(int i = 1; i < line.Count(); i++){ + if(line[i-1] == line[i]){ + repeatedLetters++; + } + } + if(repeatedLetters < 1){ + continue; + } + + int containsBadStrings = 0; + foreach(string badString in badStrings){ + if(line.Contains(badString)){ + containsBadStrings++; + } + } + if(containsBadStrings > 0){ + continue; + } + + goodStrings++; +} +Console.WriteLine("Part 1: " + goodStrings); + +goodStrings = 0; +foreach(string line in File.ReadLines("input.txt")){ + int repeatedPairs = 0; + for(int i = 1; i < line.Count(); i++){ + string currentPair = (line[i-1].ToString() + line[i].ToString()); + int numMatches = Regex.Matches(line, currentPair).Count(); + if(numMatches > 1){ + repeatedPairs++; + } + } + if(repeatedPairs<1){ + continue; + } + int repeatedLettersPart2 = 0; + for(int i = 0; i < line.Count()-2; i++){ + if(line[i+2] == line[i]){ + repeatedLettersPart2++; + } + } + if(repeatedLettersPart2 < 1){ + continue; + } + + goodStrings++; + +} +Console.WriteLine("Part 2: " + goodStrings);