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

18 lines
652 B
C#
Raw Permalink Normal View History

2022-12-03 05:55:49 +00:00
namespace AOC2015;
/// <summary>
2022-12-03 05:41:38 +00:00
/// Day 8: <a href="https://adventofcode.com/2015/day/8"/>
/// </summary>
2023-09-20 18:38:58 +00:00
public sealed partial class Day08() : Day(2015, 8, "Matchsticks")
{
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-13 19:12:09 +00:00
public override object Part2() => Input.Sum(EncodedCount) - Input.Sum(line => line.Length);
}