2015 day 5
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ade1148cc0
commit
48d6f0eaa3
|
@ -10,6 +10,7 @@ public class Test2015
|
|||
[DataRow(typeof(Day02),"1586300", "3737498")]
|
||||
[DataRow(typeof(Day03), "2081", "2341")]
|
||||
// [DataRow(typeof(Day04), "346386", "9958218")]
|
||||
[DataRow(typeof(Day05), "258", "53")]
|
||||
public void TestAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
|
@ -20,6 +21,7 @@ public class Test2015
|
|||
[DataRow(typeof(Day02), "58", "34")]
|
||||
[DataRow(typeof(Day03), "2", "11")]
|
||||
// [DataRow(typeof(Day04), "609043", "6742839")]
|
||||
[DataRow(typeof(Day05), "1", "1")]
|
||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.UseTestInput = true;
|
||||
|
|
|
@ -3,13 +3,39 @@
|
|||
/// <summary>
|
||||
/// Day 5: <see href="https://adventofcode.com/2015/day/5"/>
|
||||
/// </summary>
|
||||
public sealed class Day05 : Day
|
||||
public sealed partial class Day05 : Day
|
||||
{
|
||||
public Day05() : base(2015, 5, "Puzzle Name")
|
||||
private readonly List<string> _strings;
|
||||
private static readonly List<char> Vowels = new() { 'a', 'e', 'i', 'o', 'u' };
|
||||
|
||||
[GeneratedRegex(@"(.)\1")]
|
||||
private static partial Regex DoubleLetter();
|
||||
|
||||
[GeneratedRegex(@"(.).\1")]
|
||||
private static partial Regex LetterSandwich();
|
||||
|
||||
[GeneratedRegex(@"(..).*\1")]
|
||||
private static partial Regex TwoPairs();
|
||||
|
||||
public Day05() : base(2015, 5, "Doesn't He Have Intern-Elves For This?")
|
||||
{
|
||||
_strings = Input.Where(line => !string.IsNullOrEmpty(line)).ToList();
|
||||
}
|
||||
|
||||
public override object Part1() => "";
|
||||
public override object Part1() =>
|
||||
_strings.Count(s =>
|
||||
{
|
||||
// bad substrings
|
||||
if (s.Contains("ab") || s.Contains("cd") || s.Contains("pq") || s.Contains("xy"))
|
||||
return false;
|
||||
|
||||
public override object Part2() => "";
|
||||
// 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;
|
||||
});
|
||||
|
||||
public override object Part2() =>
|
||||
_strings.Count(s => LetterSandwich().Matches(s).Count >= 1 && TwoPairs().Matches(s).Count == 1);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
ugknbfddgicrmopn
|
||||
jchzalrnumimnmhp
|
||||
haegwjzuvuyypxyu
|
||||
dvszwmarrgswjxmb
|
||||
qjhvhtzxzqqjkmpb
|
||||
uurcxstgmygtbstg
|
||||
ieodomkazucvgmuy
|
Loading…
Reference in New Issue