2022-12-03 05:55:49 +00:00
|
|
|
namespace AOC2018;
|
2022-11-11 18:42:42 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-12-03 05:41:38 +00:00
|
|
|
/// Day 2: <a href="https://adventofcode.com/2018/day/2"/>
|
2022-11-11 18:42:42 +00:00
|
|
|
/// </summary>
|
2023-09-20 18:38:58 +00:00
|
|
|
public sealed class Day02() : Day(2018, 2, "Inventory Management System")
|
2022-11-11 18:42:42 +00:00
|
|
|
{
|
2022-12-08 19:40:40 +00:00
|
|
|
public override void ProcessInput()
|
|
|
|
{
|
|
|
|
}
|
2022-11-11 18:42:42 +00:00
|
|
|
|
2022-12-11 01:18:34 +00:00
|
|
|
private static bool HasNChars(string line, int count)
|
|
|
|
{
|
|
|
|
for (var i = 'a'; i <= 'z'; i++)
|
|
|
|
if (line.Count(c => c == i) == count)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override object Part1() =>
|
|
|
|
Input.Count(l => HasNChars(l, 2)) * Input.Count(l => HasNChars(l, 3));
|
2022-11-11 18:42:42 +00:00
|
|
|
|
2022-12-11 01:18:34 +00:00
|
|
|
public override object Part2()
|
|
|
|
{
|
|
|
|
var input = Input.ToImmutableList();
|
|
|
|
|
|
|
|
foreach (var id1 in input)
|
|
|
|
foreach (var id2 in input.Where(line2 => id1.HammingDistance(line2) == 1))
|
|
|
|
return id1.Remove(id1.Zip(id2).Indexed().First(i => i.Value.First != i.Value.Second).Key, 1);
|
|
|
|
|
|
|
|
throw new("Correct IDs not found");
|
|
|
|
}
|
|
|
|
}
|