Created
December 9, 2015 01:06
-
-
Save WiredUK/bc3f1fc646c441141dd4 to your computer and use it in GitHub Desktop.
Advent of code day 8 (LinqPad)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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