Space on the sleigh is limited this year, and so Santa will be bringing his list as a digital copy. He needs to know how much space it will take up when stored.
It is common in many programming languages to provide a way to escape special characters in strings. For example, C, JavaScript, Perl, Python, and even PHP handle special characters in very similar ways.
Read the full puzzle.
using System.Linq;
using System.Text.RegularExpressions;
namespace AdventOfCode.Y2015.Day08;
[ProblemName("Matchsticks")]
class Solution : Solver {
public object PartOne(string input) =>
(from line in input.Split('\n')
let u = Regex.Unescape(line.Substring(1, line.Length - 2))
select line.Length - u.Length).Sum();
public object PartTwo(string input) =>
(from line in input.Split('\n')
let u = "\"" + line.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""
select u.Length - line.Length).Sum();
}
Please ☆ my repo if you like it!