Skip to content

Instantly share code, notes, and snippets.

@WiredUK
Created December 9, 2015 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WiredUK/bc3f1fc646c441141dd4 to your computer and use it in GitHub Desktop.
Save WiredUK/bc3f1fc646c441141dd4 to your computer and use it in GitHub Desktop.
Advent of code day 8 (LinqPad)
void Main()
{
Part1();
Part2();
}
void Part1()
{
var lines = File.ReadAllLines(@"C:\Users\David\Documents\LINQPad Queries\input-day8.txt");
var totalLength = 0;
var parsedLength = 0;
lines.ToList().ForEach(line =>
{
totalLength += line.Length;
line = line.Replace(@"\\", @"X").Replace(@"\""", @"""");
parsedLength += line.Length - 2 - (line.Count(c => c == '\\')*3);
});
(totalLength - parsedLength).Dump("Part 1");
}
public void Part2()
{
var lines = File.ReadAllLines(@"C:\Users\David\Documents\LINQPad Queries\input-day8.txt");
var totalLength = 0;
var parsedLength = 0;
lines.ToList().ForEach(line =>
{
totalLength += line.Length;
line = @"""" + line.Replace(@"""", @"""""").Replace(@"\", @"\\") + @"""";
parsedLength += line.Length;
});
(parsedLength - totalLength).Dump("Part 2");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment