initial add to repository
This commit is contained in:
136
2018_03/Program.cs
Normal file
136
2018_03/Program.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using static System.Console;
|
||||
|
||||
namespace _2018_03
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int xDim = 0;
|
||||
int yDim = 0;
|
||||
//string indata = File.ReadAllText(@"I:\Adventofcode_181201\data181203.txt");
|
||||
string indata = File.ReadAllText(@"D:\AdventOfCode\data\2018_03_data.txt");
|
||||
//string indata = "#1 @ 1,3: 4x4\r\n#2 @ 3,1: 4x4\r\n#3 @ 5,5: 2x2\r\n";
|
||||
|
||||
string[] resTab = indata.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
int[,] fabricArea = null;
|
||||
|
||||
List<ElveSpace> areas = new List<ElveSpace>();
|
||||
|
||||
|
||||
foreach (var str in resTab)
|
||||
{
|
||||
areas.Add(new ElveSpace(str));
|
||||
}
|
||||
|
||||
foreach (ElveSpace es in areas)
|
||||
{
|
||||
// WriteLine($"Nr {es.SpaceNr} , xpos: {es.xPos} , ypos: {es.yPos} , width: {es.width} , higth: {es.highth} ");
|
||||
|
||||
if (es.bigWidth > xDim)
|
||||
{
|
||||
xDim = es.bigWidth;
|
||||
}
|
||||
if (es.bigHeight > yDim)
|
||||
{
|
||||
yDim = es.bigHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WriteLine($"the big picture : {xDim} X {yDim}");
|
||||
fabricArea = new int[xDim, yDim];
|
||||
foreach (ElveSpace es in areas)
|
||||
{
|
||||
es.AllocateArea(fabricArea);
|
||||
}
|
||||
int concurredArea = 0;
|
||||
for (int x = 0; x < xDim; x++)
|
||||
{
|
||||
for (int y = 0; y < yDim; y++)
|
||||
{
|
||||
if (fabricArea[x, y] > 1)
|
||||
{
|
||||
concurredArea += 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WriteLine($"dubbeltecknat : {concurredArea} square-inches av {xDim * yDim} square-inches");
|
||||
|
||||
foreach (ElveSpace es in areas)
|
||||
{
|
||||
if (es.CheckNotOverLap(fabricArea))
|
||||
{
|
||||
WriteLine($"Area nr: {es.SpaceNr} is free from concurrers !");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ElveSpace
|
||||
{
|
||||
public int SpaceNr { get; set; }
|
||||
|
||||
public int xPos { get; set; }
|
||||
public int yPos { get; set; }
|
||||
public int width { get; set; }
|
||||
public int highth { get; set; }
|
||||
public int bigWidth { get; set; }
|
||||
public int bigHeight { get; set; }
|
||||
|
||||
|
||||
public ElveSpace(string spcData)
|
||||
{
|
||||
string[] fields = spcData.Split(new char[] { '#', '@', ',', ':', 'x' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
SpaceNr = int.Parse(fields[0]);
|
||||
xPos = int.Parse(fields[1]);
|
||||
yPos = int.Parse(fields[2]);
|
||||
width = int.Parse(fields[3]);
|
||||
highth = int.Parse(fields[4]);
|
||||
|
||||
bigWidth = xPos + width;
|
||||
bigHeight = yPos + highth;
|
||||
}
|
||||
|
||||
public void AllocateArea(int[,] fabricArea)
|
||||
{
|
||||
for (int i = xPos; i < xPos + width; i++)
|
||||
{
|
||||
for (int j = yPos; j < yPos + highth; j++)
|
||||
{
|
||||
fabricArea[i, j] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckNotOverLap(int[,] fabricArea)
|
||||
{
|
||||
bool answer = true;
|
||||
for (int i = xPos; i < xPos + width; i++)
|
||||
{
|
||||
for (int j = yPos; j < yPos + highth; j++)
|
||||
{
|
||||
if (fabricArea[i, j] > 1)
|
||||
{
|
||||
answer = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (answer == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user