From df11d118a966711f0f40bb91a5e16a30829e8f4a Mon Sep 17 00:00:00 2001 From: "marcus@weifer.de" Date: Mon, 5 Dec 2022 12:43:11 +0100 Subject: [PATCH] =?UTF-8?q?Projektdateien=20hinzuf=C3=BCgen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Kalender.sln | 27 +++++ Kalender/App.config | 6 + Kalender/Kalender.csproj | 57 +++++++++ Kalender/Program.cs | 17 +++ Kalender/Properties/AssemblyInfo.cs | 36 ++++++ Kalender/day1.cs | 56 +++++++++ Kalender/day2.cs | 181 ++++++++++++++++++++++++++++ Kalender/day3.cs | 90 ++++++++++++++ Kalender/day5.cs | 138 +++++++++++++++++++++ 9 files changed, 608 insertions(+) create mode 100644 Kalender.sln create mode 100644 Kalender/App.config create mode 100644 Kalender/Kalender.csproj create mode 100644 Kalender/Program.cs create mode 100644 Kalender/Properties/AssemblyInfo.cs create mode 100644 Kalender/day1.cs create mode 100644 Kalender/day2.cs create mode 100644 Kalender/day3.cs create mode 100644 Kalender/day5.cs diff --git a/Kalender.sln b/Kalender.sln new file mode 100644 index 0000000..c7d734e --- /dev/null +++ b/Kalender.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kalender", "Kalender\Kalender.csproj", "{7F620304-6022-4939-A6D9-01A9BBC907A9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{4955BCA5-D3BC-4562-BC34-070B7214820F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7F620304-6022-4939-A6D9-01A9BBC907A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F620304-6022-4939-A6D9-01A9BBC907A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F620304-6022-4939-A6D9-01A9BBC907A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F620304-6022-4939-A6D9-01A9BBC907A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {42F2B407-DB71-47A7-918C-B80AD8F0F273} + EndGlobalSection +EndGlobal diff --git a/Kalender/App.config b/Kalender/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Kalender/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Kalender/Kalender.csproj b/Kalender/Kalender.csproj new file mode 100644 index 0000000..ae4c1bf --- /dev/null +++ b/Kalender/Kalender.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {7F620304-6022-4939-A6D9-01A9BBC907A9} + Exe + Kalender + Kalender + v4.7.2 + 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/Kalender/Program.cs b/Kalender/Program.cs new file mode 100644 index 0000000..627b01d --- /dev/null +++ b/Kalender/Program.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Kalender +{ + internal class Program + { + static void Main(string[] args) + { + day5.getMoveLine(); + Console.ReadKey(); + } + } +} diff --git a/Kalender/Properties/AssemblyInfo.cs b/Kalender/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bd0f956 --- /dev/null +++ b/Kalender/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Kalender")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Kalender")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("7f620304-6022-4939-a6d9-01a9bbc907a9")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Kalender/day1.cs b/Kalender/day1.cs new file mode 100644 index 0000000..1cc046e --- /dev/null +++ b/Kalender/day1.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Kalender +{ + internal class day1 + { + static public void read() + { + string file = "./../../../../day1.txt"; + string text = File.ReadAllText(file); + string[] lines = text.Split( + new string[] { Environment.NewLine }, + StringSplitOptions.None); + List count = new List(); + int counter = 0; + foreach (string line in lines) + { + + if(line.Length != 0) + { + counter += Convert.ToInt32(line); + } + else + { + count.Add(counter); + counter = 0; + } + } + count.Sort(); + foreach(int number in count) + { + // Console.WriteLine($"{number}"); + } + + counter = 0; + count.Reverse(); + for (int i = 0; i < 3; i++) + { + counter += count[i]; + } + + Console.WriteLine(counter); + } + + + } + + } + diff --git a/Kalender/day2.cs b/Kalender/day2.cs new file mode 100644 index 0000000..b3307a5 --- /dev/null +++ b/Kalender/day2.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Kalender +{ + /*A = Stein, B = Papier, C = Schere + X = Stein, Y = Papier, Z = Schere + Stein = 1, Papier = 2, Schere = 3 + 3 Unentschieden, 6 Sieg*/ + internal class day2 + { + static int counter = 0; + static string[] lines; + static public void day_2_einlesen() + { + string file = "./../../../../day2.txt"; + string text = File.ReadAllText(file); + lines = text.Split( + new string[] { Environment.NewLine }, + StringSplitOptions.None); + } + + static public void day2_partOne() + { + day_2_einlesen(); + foreach (string line in lines) + { + string ausgang = ""; + + if (line[0] == 'A' && line[2] == 'X') + { + ausgang = "unentschieden"; + + } + else if (line[0] == 'A' && line[2] == 'Y') + { + ausgang = "gewonnen"; + } + else if (line[0] == 'A' && line[2] == 'Z') + { + ausgang = "verloren"; + } + else if (line[0] == 'B' && line[2] == 'X') + { + ausgang = "verloren"; + } + else if (line[0] == 'B' && line[2] == 'Y') + { + ausgang = "unentschieden"; + } + else if (line[0] == 'B' && line[2] == 'Z') + { + ausgang = "gewonnen"; + } + else if (line[0] == 'C' && line[2] == 'X') + { + ausgang = "gewonnen"; + } + else if (line[0] == 'C' && line[2] == 'Y') + { + ausgang = "verloren"; + } + else if (line[0] == 'C' && line[2] == 'Z') + { + ausgang = "unentschieden"; + } + + counter_(ausgang, line[2]); + } + Console.WriteLine($"Endergebnis: {counter}"); + } + static private void counter_(string ausgang, char buchstabe) + { + switch (ausgang) + { + case "gewonnen": + counter += 6; + break; + case "verloren": + counter += 0; + break; + case "unentschieden": + counter += 3; + break; + } + + switch (buchstabe) + { + case 'X': + counter += 1; + break; + case 'Y': + counter += 2; + break; + case 'Z': + counter += 3; + break; + } + } + static public void day2_partTwo() + { + day_2_einlesen(); + + foreach (string line in lines) + { + string ausgang = ""; + if (line[0] == 'A' && line[2] == 'X') + { + ausgang = "schere"; + + } + else if (line[0] == 'A' && line[2] == 'Y') + { + ausgang = "stein"; + } + else if (line[0] == 'A' && line[2] == 'Z') + { + ausgang = "papier"; + } + else if (line[0] == 'B' && line[2] == 'X') + { + ausgang = "stein"; + } + else if (line[0] == 'B' && line[2] == 'Y') + { + ausgang = "papier"; + } + else if (line[0] == 'B' && line[2] == 'Z') + { + ausgang = "schere"; + } + else if (line[0] == 'C' && line[2] == 'X') + { + ausgang = "papier"; + } + else if (line[0] == 'C' && line[2] == 'Y') + { + ausgang = "schere"; + } + else if (line[0] == 'C' && line[2] == 'Z') + { + ausgang = "stein"; + } + counter_part_two(ausgang, line[2]); + } + Console.WriteLine($"Endergebnis: {counter}"); + } + static private void counter_part_two(string ausgang, char buchstabe) + { + switch (ausgang) + { + case "stein": + counter += 1; + break; + case "papier": + counter += 2; + break; + case "schere": + counter += 3; + break; + } + + switch (buchstabe) + { + case 'X': + counter += 0; + break; + case 'Y': + counter += 3; + break; + case 'Z': + counter += 6; + break; + } + } + } +} diff --git a/Kalender/day3.cs b/Kalender/day3.cs new file mode 100644 index 0000000..5d2e0b5 --- /dev/null +++ b/Kalender/day3.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Kalender +{ + internal class day3 + { + static string file = "../../../../day3.txt"; + static string letters = "0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + static string[] lines = File.ReadAllLines(file); + static List bag1 = new List(); + static List bag2 = new List(); + static int sum = 0; + + public static void day3_part1() + { + Console.WriteLine(letters.Count()); + + + foreach (string line in lines) + { + bag1.Add(line.Substring(0, (line.Length / 2))); + bag2.Add(line.Substring(line.Length / 2)); + } + + for(int i = 0; i < bag1.Count; i++) + { + foreach(char c in bag1[i]) + { + + if (bag2[i].Contains(c)) + { + for(int j = 0; j < letters.Count(); j++) + { + if(letters[j] == c) + { + sum += j; + } + } + Console.WriteLine(c); + break; + } + + } + } + Console.WriteLine(sum); + } + public static void day3_part2() + { + int counter = 0; + int start = 0; + char bla = ' '; + + while (counter < lines.Count()) + { + + foreach(char c in lines[start]) + { + if (lines[start].Contains(c) && lines[start+1].Contains(c) && lines[start + 2].Contains(c)) + { + bla = c; + break; + } + } + for (int j = 0; j < letters.Count(); j++) + { + if (letters[j] == bla) + { + sum += j; + } + } + + Console.WriteLine(sum); + start += 3; + counter +=3; + + } + + } + } + } + + diff --git a/Kalender/day5.cs b/Kalender/day5.cs new file mode 100644 index 0000000..1670f1f --- /dev/null +++ b/Kalender/day5.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace Kalender +{ + internal class day5 + { + static List> lists = new List>(); + + // Create Base lists in "lists" + public static void createBaseList() + { + string file = "../../../../day5_base.txt"; + string[] lines = File.ReadAllLines(file); + + // 9 Columns in file day5_base + int column = 9; + + for (int i = 0; i < column; i++) + { + lists.Add(new List()); + } + + // If on this index a char, @ it to a specific list + foreach (string _line in lines) + { + if (_line[1] != ' ') + { + lists[0].Add(_line[1]); + + } + if (_line[5] != ' ') + { + lists[1].Add(_line[5]); + + } + if (_line[9] != ' ') + { + lists[2].Add(_line[9]); + + } + if (_line[13] != ' ') + { + lists[3].Add(_line[13]); + + } + if (_line[17] != ' ') + { + lists[4].Add(_line[17]); + + } + if (_line[21] != ' ') + { + lists[5].Add(_line[21]); + + } + if (_line[25] != ' ') + { + lists[6].Add(_line[25]); + + } + if (_line[29] != ' ') + { + lists[7].Add(_line[29]); + + } + if (_line[33] != ' ') + { + lists[8].Add(_line[33]); + + } + + + } + + } + + + static public void getMoveLine() + { + createBaseList(); + string file = "../../../../day5.txt"; + string[] lines = File.ReadAllLines(file); + + + foreach(string line in lines) + { + + + // Mover + List splitTheLineList = new List(); + splitTheLineList = splitTheLine(line); + + int moveFrom = splitTheLineList[1] -1; + int moveAll = splitTheLineList[0]; + int moveTo = splitTheLineList[2] -1; + + + for(int i = 0; i < moveAll; i++) + { + char x = lists[moveFrom].ElementAt(0); + lists[moveFrom].RemoveAt(0); + lists[moveTo].Reverse(); + lists[moveTo].Add(x); + lists[moveTo].Reverse(); + } + } + foreach (List _charList in lists) + { + + Console.WriteLine(_charList[0]); + } + } + + // Removes the Words, and store the needed Numbers + static List splitTheLine(string line) + { + List list = new List(); + line = line.Replace("move ", ""); + line = line.Replace("from ", ""); + line = line.Replace("to ", ""); + + var a =line.Split(' '); + foreach (string i in a) + { + list.Add(Convert.ToInt32(i)); + } + return list; + } + } + +}