ben
/
aoc
1
0
Fork 0

2015 day 19
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2023-09-20 16:29:42 -04:00
parent 35ed5e0dd7
commit b87e05fff0
4 changed files with 44 additions and 3 deletions

View File

@ -24,6 +24,7 @@ public class Test2015
[DataRow(typeof(Day16), "103", "405")]
[DataRow(typeof(Day17), "1304", "18")]
[DataRow(typeof(Day18), "1061", "1006")]
[DataRow(typeof(Day19), "576", "207")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);
@ -42,6 +43,7 @@ public class Test2015
[DataRow(typeof(Day10), "237746", "3369156")]
[DataRow(typeof(Day13), "330", "286")]
[DataRow(typeof(Day15), "62842880", "57600000")]
[DataRow(typeof(Day19), "4", "2")]
public void CheckTestInputs(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2, true);

View File

@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="morelinq" Version="3.4.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@ -1,3 +1,5 @@
using MoreLinq;
namespace AOC2015;
/// <summary>
@ -5,11 +7,42 @@ namespace AOC2015;
/// </summary>
public sealed class Day19() : Day(2015, 19, "Medicine for Rudolph")
{
private IEnumerable<string[]>? _rules;
private string? _compound;
public override void ProcessInput()
{
var i = Input.Split("").ToList();
_rules = i[0].Select(r => r.Split(" => "));
_compound = i[1].Single();
}
public override object Part1() => "";
private int CountSubstring(string needle)
{
var count = 0;
for (var i = _compound!.IndexOf(needle, StringComparison.InvariantCulture);
i >= 0;
++count, i = _compound.IndexOf(needle, i + 1, StringComparison.InvariantCulture))
{
}
public override object Part2() => "";
}
return count;
}
public override object Part1()
{
HashSet<string> compounds = new();
foreach (var rule in _rules!)
foreach (var match in Regex.EnumerateMatches(_compound, rule[0]))
compounds.Add(_compound!.Remove(match.Index, rule[0].Length).Insert(match.Index, rule[1]));
return compounds.Count;
}
public override object Part2() =>
_compound!.Count(char.IsUpper)
- CountSubstring("Rn")
- CountSubstring("Ar")
- 2 * CountSubstring("Y")
- 1;
}

View File

@ -0,0 +1,5 @@
H => HO
H => OH
O => HH
HOH