Compare commits
10 Commits
6935399150
...
32f529dc22
| Author | SHA1 | Date |
|---|---|---|
|
|
32f529dc22 | |
|
|
2b80257de8 | |
|
|
cf88d6ab13 | |
|
|
3544bbec51 | |
|
|
b8ad7c70aa | |
|
|
e105d05a1a | |
|
|
f0fe63d146 | |
|
|
0629ec1111 | |
|
|
5d3d100d4f | |
|
|
0b53a480f6 |
|
|
@ -4,4 +4,13 @@
|
||||||
**/debug/
|
**/debug/
|
||||||
**/target/
|
**/target/
|
||||||
**/*rs.bk
|
**/*rs.bk
|
||||||
**/calibration_document.txt
|
**/calibration_document.txt
|
||||||
|
**/.vsidx
|
||||||
|
**/.suo
|
||||||
|
/CSharp/AdventOfCode/AdventOfCode/obj
|
||||||
|
/CSharp/AdventOfCode/AdventOfCode/bin
|
||||||
|
/CSharp/AdventOfCode/.vs
|
||||||
|
/CSharp/AdventOfCode/DayOne/obj
|
||||||
|
/CSharp/AdventOfCode/DayOne/bin
|
||||||
|
/CSharp/AdventOfCode/DayTwo/obj
|
||||||
|
/CSharp/AdventOfCode/DayTwo/bin
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.4.33122.133
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode", "AdventOfCode\AdventOfCode.csproj", "{4D56E1C0-374C-446F-A0FD-42048ADE935D}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DayOne", "DayOne\DayOne.csproj", "{0988CC6B-5B4F-4CC7-814A-C07D27244099}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DayTwo", "DayTwo\DayTwo.csproj", "{61C6C698-A71A-40A4-A6F1-8096D2FDB9E6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4D56E1C0-374C-446F-A0FD-42048ADE935D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4D56E1C0-374C-446F-A0FD-42048ADE935D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4D56E1C0-374C-446F-A0FD-42048ADE935D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4D56E1C0-374C-446F-A0FD-42048ADE935D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0988CC6B-5B4F-4CC7-814A-C07D27244099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0988CC6B-5B4F-4CC7-814A-C07D27244099}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0988CC6B-5B4F-4CC7-814A-C07D27244099}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0988CC6B-5B4F-4CC7-814A-C07D27244099}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{61C6C698-A71A-40A4-A6F1-8096D2FDB9E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{61C6C698-A71A-40A4-A6F1-8096D2FDB9E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{61C6C698-A71A-40A4-A6F1-8096D2FDB9E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{61C6C698-A71A-40A4-A6F1-8096D2FDB9E6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {D68AC081-FF6A-4D9B-B3C3-91B8B49A3B8A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DayOne\DayOne.csproj" />
|
||||||
|
<ProjectReference Include="..\DayTwo\DayTwo.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="RandomFiles\calibraciones.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="RandomFiles\cubes.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
using DayOne;
|
||||||
|
using DayTwo;
|
||||||
|
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
|
|
||||||
|
//var calibrator = new CalibratorReader(@"RandomFiles\calibrations.txt");
|
||||||
|
//var calibrationFound = calibrator.ObtainCalibrationValue();
|
||||||
|
|
||||||
|
//Console.WriteLine($"The calibration found was {calibrationFound}");
|
||||||
|
|
||||||
|
var gameMaster = new CubeGameMaster(@"RandomFiles\cubes.txt");
|
||||||
|
|
||||||
|
var sumOfIds = gameMaster.ObtainSumOfValidGames();
|
||||||
|
Console.WriteLine($"Sum of the Ids is {sumOfIds}");
|
||||||
|
Console.ReadLine();
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
namespace AdventOfCode;
|
||||||
|
|
||||||
|
public class CalibratorEvaluator
|
||||||
|
{
|
||||||
|
public static int ObtainLineCalibration(string line)
|
||||||
|
{
|
||||||
|
var firstDigit = -1;
|
||||||
|
var lastDigit = -1;
|
||||||
|
|
||||||
|
foreach (var character in line)
|
||||||
|
{
|
||||||
|
if (char.IsDigit(character))
|
||||||
|
{
|
||||||
|
firstDigit = firstDigit == -1 ? (int)char.GetNumericValue(character) : firstDigit;
|
||||||
|
lastDigit = (int)char.GetNumericValue(character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstDigit * 10 + lastDigit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
using AdventOfCode;
|
||||||
|
|
||||||
|
namespace DayOne;
|
||||||
|
|
||||||
|
public class CalibratorReader
|
||||||
|
{
|
||||||
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
|
public CalibratorReader(string filePath)
|
||||||
|
{
|
||||||
|
FilePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ObtainCalibrationValue()
|
||||||
|
{
|
||||||
|
using StreamReader reader = new StreamReader(FilePath);
|
||||||
|
var calibrationResult = 0;
|
||||||
|
while (!reader.EndOfStream)
|
||||||
|
{
|
||||||
|
// Read a line from the file
|
||||||
|
string line = reader.ReadLine() ?? "Something failed";
|
||||||
|
|
||||||
|
calibrationResult = calibrationResult + CalibratorEvaluator.ObtainLineCalibration(line);
|
||||||
|
}
|
||||||
|
return calibrationResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
namespace DayTwo;
|
||||||
|
|
||||||
|
public class CubeGameMaster
|
||||||
|
{
|
||||||
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
|
public CubeGameMaster(string filePath)
|
||||||
|
{
|
||||||
|
FilePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ObtainSumOfValidGames()
|
||||||
|
{
|
||||||
|
using StreamReader reader = new StreamReader(FilePath);
|
||||||
|
var sumOfValidGames = 0;
|
||||||
|
while (!reader.EndOfStream)
|
||||||
|
{
|
||||||
|
// Read a line from the file
|
||||||
|
string line = reader.ReadLine() ?? "Something failed";
|
||||||
|
var game = new Game(line);
|
||||||
|
|
||||||
|
sumOfValidGames += game.GetIdIfValid();
|
||||||
|
}
|
||||||
|
return sumOfValidGames;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
namespace DayTwo;
|
||||||
|
|
||||||
|
public class Game
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public ICollection<string> Steps { get; set; }
|
||||||
|
|
||||||
|
private const int BLUE = 14;
|
||||||
|
private const int RED = 12;
|
||||||
|
private const int GREEN = 13;
|
||||||
|
|
||||||
|
public Game(string line)
|
||||||
|
{
|
||||||
|
var headers = line.Split(':');
|
||||||
|
|
||||||
|
var id = headers[0].Split(' ')[1];
|
||||||
|
|
||||||
|
Id = int.Parse(id);
|
||||||
|
|
||||||
|
Steps = headers[1].Split(';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetIdIfValid()
|
||||||
|
{
|
||||||
|
if (IsGameValid())
|
||||||
|
{
|
||||||
|
return Id;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsGameValid()
|
||||||
|
{
|
||||||
|
foreach (var step in Steps)
|
||||||
|
{
|
||||||
|
var colorDictionary = new Dictionary<string, int>();
|
||||||
|
var colorValues = step.Split(",");
|
||||||
|
foreach (var colorNumber in colorValues)
|
||||||
|
{
|
||||||
|
var separatedValues = colorNumber.Split(" ");
|
||||||
|
colorDictionary.Add(separatedValues[2], int.Parse(separatedValues[1]));
|
||||||
|
}
|
||||||
|
foreach (var colors in colorDictionary)
|
||||||
|
{
|
||||||
|
switch (colors.Key)
|
||||||
|
{
|
||||||
|
case "red":
|
||||||
|
if (colors.Value > RED) return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "green":
|
||||||
|
if (colors.Value > GREEN) return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "blue":
|
||||||
|
if (colors.Value > BLUE) return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue