2022-12-03 05:55:49 +00:00
|
|
|
namespace AOC2015;
|
2022-11-11 18:42:42 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-12-03 05:41:38 +00:00
|
|
|
/// Day 5: <a href="https://adventofcode.com/2015/day/5"/>
|
2022-11-11 18:42:42 +00:00
|
|
|
/// </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?")
|
2022-11-11 18:42:42 +00:00
|
|
|
{
|
2023-12-01 07:30:47 +00:00
|
|
|
private static readonly List<char> Vowels = ['a', 'e', 'i', 'o', 'u'];
|
|
|
|
private List<string> _strings = [];
|
2022-12-08 19:40:40 +00:00
|
|
|
|
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 18:42:42 +00:00
|
|
|
|
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 18:42:42 +00:00
|
|
|
|
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);
|
2022-11-11 18:42:42 +00:00
|
|
|
}
|