using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Day2 { static void PartA() { //Day 2! string path = Directory.GetCurrentDirectory() + "/input.txt"; List lines = new List(); using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { lines.Add(sr.ReadLine()); } } int total = 0; foreach (string s in lines) { string[] subs = s.Split('-', ' ', ':'); int low = Int32.Parse(subs[0]); int high = Int32.Parse(subs[1]); char c = subs[2][0]; int count = subs[4].Count(x => x == c); if (count >= low && count <= high) total++; } Console.WriteLine(total); } static void PartB() { //Day 2! string path = Directory.GetCurrentDirectory() + "/input.txt"; List lines = new List(); using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { lines.Add(sr.ReadLine()); } } int total = 0; foreach (string s in lines) { string[] subs = s.Split('-', ' ', ':'); int low = Int32.Parse(subs[0]); int high = Int32.Parse(subs[1]); char c = subs[2][0]; char a = subs[4][low - 1]; char b = subs[4][high - 1]; if ((a == c) ^ (b == c)) total++; } Console.WriteLine(total); } }