Skip to content

Instantly share code, notes, and snippets.

@keithn
Created December 3, 2018 06:27
Show Gist options
  • Save keithn/10e9379f7b1693d913e7d3959024dc84 to your computer and use it in GitHub Desktop.
Save keithn/10e9379f7b1693d913e7d3959024dc84 to your computer and use it in GitHub Desktop.
private static void Day3P1P2()
{
var data = File.ReadAllLines("Day3.txt");
var fabric = new Dictionary<(int,int), List<int>>();
foreach (var line in data)
{
var numbers = line.Split(new[] {'#', '@', ',', ':', 'x', ' '}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
var id = numbers[0];
var left = numbers[1];
var top = numbers[2];
var width = numbers[3];
var height = numbers[4];
for (int x = left; x < left + width; x++)
{
for (int y = top; y < top + height; y++)
{
if (!fabric.ContainsKey((x, y)))
{
fabric.Add((x,y), new List<int>());
}
fabric[(x,y)].Add(id);
}
}
}
var n = fabric.Count(e => e.Value.Count > 1);
Console.WriteLine(n);
var overlapping = fabric.Where(e => e.Value.Count > 1).SelectMany(e => e.Value).Distinct().ToList();
Console.WriteLine(Enumerable.Range(1,data.Length).FirstOrDefault(h => !overlapping.Contains(h)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment