my advent of code solutions
at main 30 lines 921 B view raw
1namespace Solutions._2018; 2 3/// <summary> 4/// Day 2: <a href="https://adventofcode.com/2018/day/2"/> 5/// </summary> 6public sealed class Day02InventoryManagementSystem() : Day(2018, 2, "Inventory Management System") 7{ 8 private static bool HasNChars(string line, int count) 9 { 10 for (var i = 'a'; i <= 'z'; i++) 11 if (line.Count(c => c == i) == count) 12 return true; 13 14 return false; 15 } 16 17 public override object Part1() => 18 Input.Count(l => HasNChars(l, 2)) * Input.Count(l => HasNChars(l, 3)); 19 20 public override object Part2() 21 { 22 var input = Input.ToImmutableList(); 23 24 foreach (var id1 in input) 25 foreach (var id2 in input.Where(line2 => id1.HammingDistance(line2) == 1)) 26 return id1.Remove(id1.Zip(id2).Indexed().First(i => i.Value.First != i.Value.Second).Key, 1); 27 28 throw new("Correct IDs not found"); 29 } 30}