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 8: <a href="https://adventofcode.com/2015/day/8"/>
|
2022-11-11 18:42:42 +00:00
|
|
|
/// </summary>
|
2023-09-20 18:38:58 +00:00
|
|
|
public sealed partial class Day08() : Day(2015, 8, "Matchsticks")
|
2022-11-11 18:42:42 +00:00
|
|
|
{
|
2023-09-20 18:38:58 +00:00
|
|
|
[GeneratedRegex("""^"(\\x..|\\.|.)*"$""")]
|
2022-11-13 19:12:09 +00:00
|
|
|
private static partial Regex CharSet();
|
|
|
|
|
2023-09-20 18:38:58 +00:00
|
|
|
private static int CharCount(string arg) => CharSet().Match(arg).Groups[1].Captures.Count;
|
|
|
|
private static int EncodedCount(string arg) => 2 + arg.Sum(c => c is '\\' or '\"' ? 2 : 1);
|
2022-11-13 19:12:09 +00:00
|
|
|
|
|
|
|
public override object Part1() => Input.Sum(line => line.Length) - Input.Sum(CharCount);
|
2022-11-11 18:42:42 +00:00
|
|
|
|
2022-11-13 19:12:09 +00:00
|
|
|
public override object Part2() => Input.Sum(EncodedCount) - Input.Sum(line => line.Length);
|
2022-11-11 18:42:42 +00:00
|
|
|
}
|