From d8ea4079ece28769f4d4e051a46bdabee157b403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 15 Dec 2018 09:44:55 +0100 Subject: [PATCH] initial add to repository --- 2017_01.sln | 25 ---- 2017_01/Program.cs | 71 +++++++++++ 2018_01/2018_01.csproj | 53 ++++++++ 2018_01/App.config | 6 + 2018_01/Program.cs | 60 +++++++++ 2018_01/Properties/AssemblyInfo.cs | 36 ++++++ 2018_02/2018_02.csproj | 53 ++++++++ 2018_02/App.config | 6 + 2018_02/Program.cs | 136 ++++++++++++++++++++ 2018_02/Properties/AssemblyInfo.cs | 36 ++++++ 2018_03/2018_03.csproj | 53 ++++++++ 2018_03/App.config | 6 + 2018_03/Program.cs | 136 ++++++++++++++++++++ 2018_03/Properties/AssemblyInfo.cs | 36 ++++++ 2018_04/2018_04.csproj | 98 +++++++++++++++ 2018_04/App.config | 6 + 2018_04/App.xaml | 9 ++ 2018_04/App.xaml.cs | 17 +++ 2018_04/MainWindow.xaml | 12 ++ 2018_04/MainWindow.xaml.cs | 28 +++++ 2018_04/Properties/AssemblyInfo.cs | 55 ++++++++ 2018_04/Properties/Resources.Designer.cs | 71 +++++++++++ 2018_04/Properties/Resources.resx | 117 +++++++++++++++++ 2018_04/Properties/Settings.Designer.cs | 30 +++++ 2018_04/Properties/Settings.settings | 7 ++ AdventOfCode.sln | 49 ++++++++ ConsoleApp1/2018_04.csproj | 53 ++++++++ ConsoleApp1/App.config | 6 + ConsoleApp1/Program.cs | 153 +++++++++++++++++++++++ ConsoleApp1/Properties/AssemblyInfo.cs | 36 ++++++ 30 files changed, 1435 insertions(+), 25 deletions(-) delete mode 100644 2017_01.sln create mode 100644 2018_01/2018_01.csproj create mode 100644 2018_01/App.config create mode 100644 2018_01/Program.cs create mode 100644 2018_01/Properties/AssemblyInfo.cs create mode 100644 2018_02/2018_02.csproj create mode 100644 2018_02/App.config create mode 100644 2018_02/Program.cs create mode 100644 2018_02/Properties/AssemblyInfo.cs create mode 100644 2018_03/2018_03.csproj create mode 100644 2018_03/App.config create mode 100644 2018_03/Program.cs create mode 100644 2018_03/Properties/AssemblyInfo.cs create mode 100644 2018_04/2018_04.csproj create mode 100644 2018_04/App.config create mode 100644 2018_04/App.xaml create mode 100644 2018_04/App.xaml.cs create mode 100644 2018_04/MainWindow.xaml create mode 100644 2018_04/MainWindow.xaml.cs create mode 100644 2018_04/Properties/AssemblyInfo.cs create mode 100644 2018_04/Properties/Resources.Designer.cs create mode 100644 2018_04/Properties/Resources.resx create mode 100644 2018_04/Properties/Settings.Designer.cs create mode 100644 2018_04/Properties/Settings.settings create mode 100644 AdventOfCode.sln create mode 100644 ConsoleApp1/2018_04.csproj create mode 100644 ConsoleApp1/App.config create mode 100644 ConsoleApp1/Program.cs create mode 100644 ConsoleApp1/Properties/AssemblyInfo.cs diff --git a/2017_01.sln b/2017_01.sln deleted file mode 100644 index 5fb3d46..0000000 --- a/2017_01.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.2048 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2017_01", "2017_01\2017_01.csproj", "{06CE1756-7EB8-4E0C-910C-9EC316D4E04E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {03AD54F0-CF5D-409C-801B-45464BFF9001} - EndGlobalSection -EndGlobal diff --git a/2017_01/Program.cs b/2017_01/Program.cs index 0b82d25..363026f 100644 --- a/2017_01/Program.cs +++ b/2017_01/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,6 +11,76 @@ namespace _2017_01 { static void Main(string[] args) { + var Indata = File.ReadAllText(@"I:\Adventofcode_171201\data171201.txt"); + //var Indata = "1212"; + + + MethodOne(Indata); + MethodTwo(Indata); + } + + private static void MethodOne(string Indata) + { + int value = 0; + char lastFig = ' '; + char firstFig = ' '; + foreach (var figure in Indata.ToCharArray()) + { + if (lastFig == ' ') + { + firstFig = figure; + } + if (figure == lastFig) + { + value += int.Parse(figure.ToString()); + } + lastFig = figure; + } + + if (firstFig == lastFig) + { + value += int.Parse(lastFig.ToString()); + } + + System.Console.WriteLine("--Method 1--"); + System.Console.WriteLine($"---{value}---"); + System.Console.WriteLine("----------------"); + } + + private static void MethodTwo(string Indata) + { + int value = 0; + // char lastFig = ' '; + // char firstFig = ' '; + int locPos = 0; + char[] characters = Indata.ToCharArray(); + foreach (var figure in characters) + { + if (figure == jmfChar(characters,locPos)) + { + value += int.Parse(figure.ToString()); + } + locPos++; + } + + System.Console.WriteLine("--Method 2--"); + System.Console.WriteLine($"---{value}---"); + System.Console.WriteLine("----------------"); + } + + private static char jmfChar(char[] ind, int pos) + { + char returnChr = ' '; + int chars = ind.Length / 2; + if (pos + chars > ind.Length - 1) + { + returnChr = ind[pos + chars - ind.Length]; + } + else returnChr = ind[pos + chars ]; + + return returnChr; + } + } } diff --git a/2018_01/2018_01.csproj b/2018_01/2018_01.csproj new file mode 100644 index 0000000..7cf0f8f --- /dev/null +++ b/2018_01/2018_01.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {A3A5185C-C171-42EF-A5AF-B4F9A9772231} + Exe + _2018_01 + 2018_01 + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2018_01/App.config b/2018_01/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/2018_01/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2018_01/Program.cs b/2018_01/Program.cs new file mode 100644 index 0000000..d0a9c60 --- /dev/null +++ b/2018_01/Program.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.IO; +using static System.Console; + +namespace _2018_01 +{ + class Program + { + static void Main(string[] args) + { + long longVar = 0; + int varv = 0; + bool stopped = false; + Dictionary resCheck = new Dictionary(); + string indata = File.ReadAllText(@"I:\Adventofcode_181201\data181201.txt"); + //string indata = "+1\r\n-2\r\n+3\r\n+1\r\n+1\r\n-2\r\n"; + string[] resTab = indata.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + while (!stopped) + { + varv++; + foreach (var str in resTab) + { + longVar += long.Parse(str); + WriteLine($"freq: {longVar} nr :{str.ToString()}"); + if (checkAdd(resCheck, longVar) > 1) + { + stopped = true; + break; + } + } + } + WriteLine($"The answer is {longVar} at varv {varv}"); + //foreach (var keyStr in resCheck.Keys) + //{ + // WriteLine($"freq: {keyStr} nr :{resCheck[keyStr].ToString()}"); + + //} + + } + + private static int checkAdd(Dictionary work, long newVal) + { + int times = 0; + int res; + if (work.TryGetValue(newVal.ToString(), out res)) + { + work[newVal.ToString()] += 1; + } + else + { + work.Add(newVal.ToString(), 1); + } + + times = work[newVal.ToString()]; + + return times; + } + } +} diff --git a/2018_01/Properties/AssemblyInfo.cs b/2018_01/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5bc9536 --- /dev/null +++ b/2018_01/Properties/AssemblyInfo.cs @@ -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_01")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2018_01")] +[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("a3a5185c-c171-42ef-a5af-b4f9a9772231")] + +// 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")] diff --git a/2018_02/2018_02.csproj b/2018_02/2018_02.csproj new file mode 100644 index 0000000..16696c5 --- /dev/null +++ b/2018_02/2018_02.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {03B8F28E-27B5-44BC-8051-58E2CB771E6B} + Exe + _2018_02 + 2018_02 + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2018_02/App.config b/2018_02/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/2018_02/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2018_02/Program.cs b/2018_02/Program.cs new file mode 100644 index 0000000..a4b55bc --- /dev/null +++ b/2018_02/Program.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace _2018_02 +{ + class Program + { + static void Main(string[] args) + { + int twos = 0, threes = 0; + + Dictionary resCheck = new Dictionary(); + string indata = File.ReadAllText(@"I:\Adventofcode_181201\data181202.txt"); + //string indata = "abcdef\r\nbababc\r\nabbcde\r\nabcccd\r\naabcdd\r\nabcdee\r\nababab\r\n"; + + string[] resTab = indata.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + + foreach (var boxId in resTab) + { + char[] characters = boxId.ToArray(); + Array.Sort(characters); + analyseString(characters, ref twos, ref threes); + + + } + + System.Console.WriteLine($"twos: {twos} threes: {threes} checksum: {twos * threes} "); + + SecondAnalyse(resTab); + + + } + + + private static void analyseString(char[] characters, ref int twos, ref int threes) + { + int locTwos = 0, locthrees = 0; + char lastChar = ' '; + byte cnt = 0; + foreach (var tkn in characters) + { + if (tkn == lastChar) + { + cnt++; + } + else + { + if (cnt == 2) + { + if (locTwos == 0) + locTwos++; + } + if (cnt == 3) + { + if (locthrees == 0) + { + locthrees++; + } + } + lastChar = tkn; + cnt = 1; + } + } + if (cnt == 2) + { + if (locTwos == 0) + locTwos++; + } + if (cnt == 3) + { + if (locthrees == 0) + { + locthrees++; + } + } + + twos += locTwos; + threes += locthrees; + } + + private static void SecondAnalyse(string[] restab) + { + bool ready = false; + var xlen = restab[0].Length; + + foreach (var str in restab) + { + for (int i = 0; i < xlen; i++) + { + foreach (var str2 in restab) + { + if (str2 == str) { } + else + { + string stx = "", sty = ""; + var st0 = stringUtanPos(str, i, out stx); + var st1 = stringUtanPos(str2, i, out sty); + if (st0 == st1) + { + System.Console.WriteLine($"box 1: {str},\r\nbox 2: {str2} diff chars {stx} , {sty}\r\n{st0}\r\n{st1}"); + ready = true; + break; + } + + + } + if (ready) break; + } + if (ready) break; + } + if (ready) break; + } + + + + } + + private static string stringUtanPos(string str, int i, out string stx) + { + string tmp = str; + stx = str.Substring(i, 1); + if (i > 0) + { + tmp = str.Substring(0, i) + str.Substring(i + 1); + } + else + { + tmp = str.Substring(i+1); + } + + return tmp; + } + } +} diff --git a/2018_02/Properties/AssemblyInfo.cs b/2018_02/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1cba7b5 --- /dev/null +++ b/2018_02/Properties/AssemblyInfo.cs @@ -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_02")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2018_02")] +[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("03b8f28e-27b5-44bc-8051-58e2cb771e6b")] + +// 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")] diff --git a/2018_03/2018_03.csproj b/2018_03/2018_03.csproj new file mode 100644 index 0000000..e413254 --- /dev/null +++ b/2018_03/2018_03.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {32017090-A2BF-40D9-9652-6F820D58E415} + Exe + _2018_03 + 2018_03 + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2018_03/App.config b/2018_03/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/2018_03/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2018_03/Program.cs b/2018_03/Program.cs new file mode 100644 index 0000000..386210c --- /dev/null +++ b/2018_03/Program.cs @@ -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 areas = new List(); + + + 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; + } + + } +} diff --git a/2018_03/Properties/AssemblyInfo.cs b/2018_03/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5c80fe4 --- /dev/null +++ b/2018_03/Properties/AssemblyInfo.cs @@ -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")] diff --git a/2018_04/2018_04.csproj b/2018_04/2018_04.csproj new file mode 100644 index 0000000..41b33bd --- /dev/null +++ b/2018_04/2018_04.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {59680EAD-6530-4913-A7D5-C7E1F445D05F} + WinExe + _2018_04 + 2018_04 + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/2018_04/App.config b/2018_04/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/2018_04/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2018_04/App.xaml b/2018_04/App.xaml new file mode 100644 index 0000000..7382309 --- /dev/null +++ b/2018_04/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/2018_04/App.xaml.cs b/2018_04/App.xaml.cs new file mode 100644 index 0000000..b8c793a --- /dev/null +++ b/2018_04/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace _2018_04 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/2018_04/MainWindow.xaml b/2018_04/MainWindow.xaml new file mode 100644 index 0000000..081368b --- /dev/null +++ b/2018_04/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/2018_04/MainWindow.xaml.cs b/2018_04/MainWindow.xaml.cs new file mode 100644 index 0000000..accb1d5 --- /dev/null +++ b/2018_04/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace _2018_04 +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/2018_04/Properties/AssemblyInfo.cs b/2018_04/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2c9dca4 --- /dev/null +++ b/2018_04/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 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_04")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2018_04")] +[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)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// 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")] diff --git a/2018_04/Properties/Resources.Designer.cs b/2018_04/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f78708e --- /dev/null +++ b/2018_04/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _2018_04.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_2018_04.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/2018_04/Properties/Resources.resx b/2018_04/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/2018_04/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2018_04/Properties/Settings.Designer.cs b/2018_04/Properties/Settings.Designer.cs new file mode 100644 index 0000000..1edb014 --- /dev/null +++ b/2018_04/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _2018_04.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/2018_04/Properties/Settings.settings b/2018_04/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/2018_04/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/AdventOfCode.sln b/AdventOfCode.sln new file mode 100644 index 0000000..d1a6dea --- /dev/null +++ b/AdventOfCode.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28407.52 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2017_01", "2017_01\2017_01.csproj", "{06CE1756-7EB8-4E0C-910C-9EC316D4E04E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2018_01", "2018_01\2018_01.csproj", "{A3A5185C-C171-42EF-A5AF-B4F9A9772231}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2018_02", "2018_02\2018_02.csproj", "{03B8F28E-27B5-44BC-8051-58E2CB771E6B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2018_03", "2018_03\2018_03.csproj", "{32017090-A2BF-40D9-9652-6F820D58E415}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2018_04", "ConsoleApp1\2018_04.csproj", "{7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06CE1756-7EB8-4E0C-910C-9EC316D4E04E}.Release|Any CPU.Build.0 = Release|Any CPU + {A3A5185C-C171-42EF-A5AF-B4F9A9772231}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3A5185C-C171-42EF-A5AF-B4F9A9772231}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3A5185C-C171-42EF-A5AF-B4F9A9772231}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3A5185C-C171-42EF-A5AF-B4F9A9772231}.Release|Any CPU.Build.0 = Release|Any CPU + {03B8F28E-27B5-44BC-8051-58E2CB771E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03B8F28E-27B5-44BC-8051-58E2CB771E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03B8F28E-27B5-44BC-8051-58E2CB771E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03B8F28E-27B5-44BC-8051-58E2CB771E6B}.Release|Any CPU.Build.0 = Release|Any CPU + {32017090-A2BF-40D9-9652-6F820D58E415}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32017090-A2BF-40D9-9652-6F820D58E415}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32017090-A2BF-40D9-9652-6F820D58E415}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32017090-A2BF-40D9-9652-6F820D58E415}.Release|Any CPU.Build.0 = Release|Any CPU + {7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E85B89B-15D2-4248-AE0D-DD96C84A2E5A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {03AD54F0-CF5D-409C-801B-45464BFF9001} + EndGlobalSection +EndGlobal diff --git a/ConsoleApp1/2018_04.csproj b/ConsoleApp1/2018_04.csproj new file mode 100644 index 0000000..ab9bc7d --- /dev/null +++ b/ConsoleApp1/2018_04.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {7E85B89B-15D2-4248-AE0D-DD96C84A2E5A} + Exe + ConsoleApp1 + ConsoleApp1 + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConsoleApp1/App.config b/ConsoleApp1/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/ConsoleApp1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs new file mode 100644 index 0000000..e7a8363 --- /dev/null +++ b/ConsoleApp1/Program.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using static System.Console; + +namespace _2018_04 +{ + + + class Program + { + static void Main(string[] args) + { + string[] splitter = new string[] { "[", "]" }; + + string[] resTab = File.ReadAllLines(@"D:\AdventOfCode\data\2018_04_data.txt"); + + Array.Sort(resTab); + Dictionary gdList = new Dictionary(); + GardDay gd = null; + + //[1518-11-01 00:00] Guard #10 begins shift + //[1518-11-01 00:05] falls asleep + //[1518-11-01 00:25] wakes up + //[1518-11-01 00:30] falls asleep + //[1518-11-01 00:55] wakes up + + foreach (var str in resTab) + { + if (str.Contains("#")) + { + if (gd != null) + { + WriteLine(gd.ToString()); + if (gdList.ContainsKey(gd.GardNr)) + { + for (int vekt = 0; vekt < gdList[gd.GardNr].MinTabell.Length; vekt++) + { + gdList[gd.GardNr].MinTabell[vekt] += gd.MinTabell[vekt]; + } + gdList[gd.GardNr].SleepMinutes += gd.SleepMinutes; + } + else + { + gd.fillMinTable(); + gdList.Add(gd.GardNr, gd); + } + } + gd = new GardDay(str); + // WriteLine($"Gard day = {gd.ToString()}"); + } + else + { + gd.fillNext(str); + } + } + + foreach( int key in gdList.Keys) + { + + } + //gdList.Add(gd.GardNr, gd); + + } + } + public class GardDay + { + string[] splitter = new string[] { "[", "]" }; + public int GardNr { get; set; } + public Dictionary TimeStamp { get; set; } + public int[] MinTabell { get; set; } + public int SleepMinutes { get; set; } + public void fillMinTable() + { + int saveMin = -1; + foreach (KeyValuePair pair in TimeStamp) + { + if (pair.Value == "sleep") + { + saveMin = pair.Key.Minute; + } + else + { + if (saveMin > -1) + { + + for (int i = saveMin; i < pair.Key.Minute; i++) + { + MinTabell[i]++; + SleepMinutes++; + } + } + } + + } + } + + + + public GardDay(string inRow) + { + MinTabell = new int[60]; + SleepMinutes = 0; + string outStr = ""; + fillNext(inRow, out outStr); + var xwords = outStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var ystr in xwords) + { + if (ystr.Contains("#")) + { + GardNr = int.Parse(ystr.Substring(ystr.IndexOf("#") + 1)); + } + } + } + + public void fillNext(string inRow) + { + string tmpOut = null; + fillNext(inRow, out tmpOut); + } + + public void fillNext(string inRow, out string outStr) + { + string[] xrow = inRow.Split(splitter, StringSplitOptions.RemoveEmptyEntries); + outStr = xrow[1]; + DateTime ts = DateTime.Parse(xrow[0]); + if (TimeStamp == null) + { + TimeStamp = new Dictionary(); + } + string tmpStep = "sleep"; + if (outStr.Contains("Guard") || outStr.Contains("wakes")) + { + tmpStep = "awake"; + } + + TimeStamp.Add(ts, tmpStep); + } + + public override string ToString() + { + StringBuilder outTxt = new StringBuilder(); + outTxt.Append($"gardnr {GardNr}"); + foreach (var key in TimeStamp.Keys) + { + outTxt.Append($" Time : {key}, {TimeStamp[key]}"); + } + + return outTxt.ToString(); + } + } +} \ No newline at end of file diff --git a/ConsoleApp1/Properties/AssemblyInfo.cs b/ConsoleApp1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e8eb6ea --- /dev/null +++ b/ConsoleApp1/Properties/AssemblyInfo.cs @@ -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("ConsoleApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApp1")] +[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("7e85b89b-15d2-4248-ae0d-dd96c84a2e5a")] + +// 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")]