initial add to repository
This commit is contained in:
53
2018_03/2018_03.csproj
Normal file
53
2018_03/2018_03.csproj
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{32017090-A2BF-40D9-9652-6F820D58E415}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>_2018_03</RootNamespace>
|
||||
<AssemblyName>2018_03</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
6
2018_03/App.config
Normal file
6
2018_03/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
2018_03/Properties/AssemblyInfo.cs
Normal file
36
2018_03/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("2018_03")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("2018_03")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("32017090-a2bf-40d9-9652-6f820d58e415")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user