ben
/
aoc
1
0
Fork 0
aoc/AOC2015/Day05.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2022-12-03 05:55:49 +00:00
namespace AOC2015;
/// <summary>
2022-12-03 05:41:38 +00:00
/// Day 5: <a href="https://adventofcode.com/2015/day/5"/>
/// </summary>
2023-09-20 18:38:58 +00:00
public sealed partial class Day05() : Day(2015, 5, "Doesn't He Have Intern-Elves For This?")
{
2023-12-01 07:30:47 +00:00
private static readonly List<char> Vowels = ['a', 'e', 'i', 'o', 'u'];
private List<string> _strings = [];
2022-11-11 22:02:28 +00:00
[GeneratedRegex(@"(.)\1")]
private static partial Regex DoubleLetter();
[GeneratedRegex(@"(.).\1")]
private static partial Regex LetterSandwich();
[GeneratedRegex(@"(..).*\1")]
private static partial Regex TwoPairs();
2023-12-01 07:30:47 +00:00
public override void ProcessInput() =>
2022-11-11 22:02:28 +00:00
_strings = Input.Where(line => !string.IsNullOrEmpty(line)).ToList();
2022-11-11 22:02:28 +00:00
public override object Part1() =>
_strings.Count(s =>
{
// bad substrings
if (s.Contains("ab") || s.Contains("cd") || s.Contains("pq") || s.Contains("xy"))
return false;
// must have at least 3 vowels
if (s.Count(c => Vowels.Contains(c)) < 3) return false;
// must have a double-letter somewhere
return DoubleLetter().Matches(s).Count >= 1;
});
2022-11-11 22:02:28 +00:00
public override object Part2() =>
_strings.Count(s => LetterSandwich().Matches(s).Count >= 1 && TwoPairs().Matches(s).Count == 1);
}