Skip to content

Instantly share code, notes, and snippets.

@WiredUK
Created December 2, 2015 15:11
Show Gist options
  • Save WiredUK/8cd9786521890f93f8e7 to your computer and use it in GitHub Desktop.
Save WiredUK/8cd9786521890f93f8e7 to your computer and use it in GitHub Desktop.
void Main()
{
var input = File.ReadAllLines(@"C:\Users\David\Documents\LINQPad Queries\input-day2.txt");
var totalPaper = input.Select(i => i.Split('x')).Select(i => i.Select(j => int.Parse(j)).ToList()).Select(i => 2 * i[0] * i[1] + 2 * i[0] * i[2] + 2 * i[1] * i[2] + i.OrderBy(j => j).Take(2).Aggregate((k, l) => k * l)).Sum();
totalPaper.Dump();
var totalRibbon = input.Select(i => i.Split('x')).Select(i => i.Select(j => int.Parse(j)).ToList()).Select(i => i[0]*i[1]*i[2] + i.OrderBy(j => j).Take(2).Aggregate((k, l) => 2*k + 2*l)).Sum();
totalRibbon.Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment