Created
December 3, 2018 06:27
-
-
Save keithn/10e9379f7b1693d913e7d3959024dc84 to your computer and use it in GitHub Desktop.
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
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