Projektdateien hinzufügen.

This commit is contained in:
marcus@weifer.de 2022-12-13 17:08:08 +01:00
parent 8f0b224c91
commit a1a4abcdfa
12 changed files with 5327 additions and 0 deletions

15
AdventOfCode2021.csproj Normal file
View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="inputs\day2 - Kopieren %282%29.txt" />
<None Remove="inputs\day2 - Kopieren.txt" />
</ItemGroup>
</Project>

25
AdventOfCode2021.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode2021", "AdventOfCode2021.csproj", "{86E5DDE7-1AB6-486A-A75B-594F87BC7151}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{86E5DDE7-1AB6-486A-A75B-594F87BC7151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86E5DDE7-1AB6-486A-A75B-594F87BC7151}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86E5DDE7-1AB6-486A-A75B-594F87BC7151}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86E5DDE7-1AB6-486A-A75B-594F87BC7151}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E035E8A4-FF5C-422F-A0D3-8B1AF82463CA}
EndGlobalSection
EndGlobal

4
Program.cs Normal file
View File

@ -0,0 +1,4 @@

using AdventOfCode2021;
var day = new day3("day3");

82
day1.cs Normal file
View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2021
{
internal class day1
{
string[] input;
public day1(string day)
{
input = getInput(day);
part1();
part2();
}
public string[] getInput(string day)
{
string filepath = $"../../../inputs/{day}.txt";
string[] file = File.ReadAllLines(filepath);
return file;
}
public void part1()
{
int temp = int.Parse(input[0]);
int counter = 0;
for(int i = 0; i < input.Length; i++)
{
if (int.Parse(input[i]) > temp)
{
temp = int.Parse(input[i]);
counter++;
}
else
{
temp = int.Parse(input[i]);
}
}
Console.WriteLine($"Part 1 : {counter}");
}
public void part2()
{
int temp = computeWindow(0);
int counter = 0;
for (int i = 3; i < input.Length; i++)
{
if(computeWindow(i -2) > temp)
{
counter++;
temp= computeWindow(i - 2);
}
else
{
temp = computeWindow(i - 2);
}
}
Console.WriteLine($"Part 2 : {counter}");
}
public int computeWindow(int index)
{
int window = int.Parse(input[index]) + int.Parse(input[index + 1]) + int.Parse(input[index + 2]);
return window;
}
}
}

79
day2.cs Normal file
View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2021
{
internal class day2
{
string[] input;
public day2(string day)
{
input = getInput(day);
part1();
part2();
}
public string[] getInput(string day)
{
string filepath = $"../../../inputs/{day}.txt";
string[] file = File.ReadAllLines(filepath);
return file;
}
public void part1()
{
int result = 0;
int horizontal = 0;
int depth = 0;
foreach(string line in input)
{
if (line.StartsWith("forward"))
{
horizontal += int.Parse(line.Split(' ')[1]);
}
else if (line.StartsWith("down"))
{
depth += int.Parse(line.Split(' ')[1]);
}
else if (line.StartsWith("up"))
{
depth -= int.Parse(line.Split(' ')[1]);
}
}
result = horizontal * depth;
Console.WriteLine($"Part 1: {result}");
}
public void part2()
{
int result = 0;
int horizontal = 0;
int aim = 0;
int depht = 0;
foreach (string line in input)
{
if (line.StartsWith("forward"))
{
horizontal += int.Parse(line.Split(' ')[1]);
depht += int.Parse(line.Split(' ')[1]) * aim;
}
else if (line.StartsWith("down"))
{
aim += int.Parse(line.Split(' ')[1]);
}
else if (line.StartsWith("up"))
{
aim -= int.Parse(line.Split(' ')[1]);
}
}
result = horizontal * depht;
Console.WriteLine($"Part 2: {result}");
}
}
}

85
day3.cs Normal file
View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2021
{
internal class day3
{
string[] input;
public day3(string day)
{
input = getInput(day);
part1();
part2();
}
public string[] getInput(string day)
{
string filepath = $"../../../inputs/{day}.txt";
string[] file = File.ReadAllLines(filepath);
return file;
}
public void part1()
{
var result = new StringBuilder();
var result2 = new StringBuilder();
for(int i = 0; i < input[0].Length; i++)
{
int oneCounter = 0;
int zeroCounter = 0;
for(int j = 0; j < input.Length; j++)
{
if (input[j][i] == '0')
{
zeroCounter++;
}
else
{
oneCounter++;
}
}
if (oneCounter > zeroCounter)
{
result.Append('1');
result2.Append('0');
}
else if (oneCounter < zeroCounter)
{
result.Append('0');
result2.Append('1');
}
else if(oneCounter == zeroCounter)
{
result.Append('1');
result2.Append('0');
}
}
int decResult1 = Convert.ToInt32(result.ToString(), 2);
int decResult2 = Convert.ToInt32(result2.ToString(), 2);
int finalResult = decResult1 * decResult2;
Console.WriteLine($"Part 1 : {finalResult}");
}
public void part2()
{
Console.WriteLine($"Part 2 : ");
}
}
}

36
days.cs Normal file
View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2021
{
internal class days
{
string[] input;
public days(string day)
{
input = getInput(day);
part1();
part2();
}
public string[] getInput(string day)
{
string filepath = $"../../../inputs/{day}.txt";
string[] file = File.ReadAllLines(filepath);
return file;
}
public void part1()
{
}
public void part2()
{
}
}
}

2000
inputs/day1.txt Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@


1000
inputs/day2.txt Normal file

File diff suppressed because it is too large Load Diff

1000
inputs/day3.txt Normal file

File diff suppressed because it is too large Load Diff