feat: Add day 1
This commit is contained in:
parent
319a02e0fd
commit
8e8ca67091
8 changed files with 4594 additions and 0 deletions
10
AdventOfCode2026/AdventOfCode2026.csproj
Normal file
10
AdventOfCode2026/AdventOfCode2026.csproj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
16
AdventOfCode2026/AdventOfCode2026.sln
Normal file
16
AdventOfCode2026/AdventOfCode2026.sln
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode2026", "AdventOfCode2026.csproj", "{1B2A5F8D-587F-4257-9443-1951C8D0D38A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1B2A5F8D-587F-4257-9443-1951C8D0D38A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1B2A5F8D-587F-4257-9443-1951C8D0D38A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1B2A5F8D-587F-4257-9443-1951C8D0D38A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1B2A5F8D-587F-4257-9443-1951C8D0D38A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
64
AdventOfCode2026/Day1.cs
Normal file
64
AdventOfCode2026/Day1.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
namespace AdventOfCode2026;
|
||||
|
||||
public sealed class Day1 : Solution
|
||||
{
|
||||
private const int MaxArrow = 100;
|
||||
public override string SolvePart1()
|
||||
{
|
||||
var arrow = 50;
|
||||
var zeroCounter = 0;
|
||||
IEnumerable<string> lines = InputReader.ReadLines(1);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var number = int.Parse(line[1..]);
|
||||
arrow = line.First() switch
|
||||
{
|
||||
'L' => arrow - number,
|
||||
'R' => arrow + number,
|
||||
var _ => arrow
|
||||
};
|
||||
|
||||
arrow = (arrow % MaxArrow + MaxArrow) % MaxArrow;
|
||||
if (arrow == 0)
|
||||
{
|
||||
zeroCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
return zeroCounter.ToString();
|
||||
}
|
||||
|
||||
public override string SolvePart2()
|
||||
{
|
||||
var arrow = 50;
|
||||
var zeroCounter = 0;
|
||||
IEnumerable<string> lines = InputReader.ReadLines(1);
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var number = int.Parse(line[1..]);
|
||||
zeroCounter += number / MaxArrow;
|
||||
var remainingNumber = number % MaxArrow;
|
||||
|
||||
var end = line.First() switch
|
||||
{
|
||||
'L' => arrow - remainingNumber,
|
||||
'R' => arrow + remainingNumber,
|
||||
var _ => arrow
|
||||
};
|
||||
|
||||
if (arrow != 0 && end is > MaxArrow or < 0)
|
||||
{
|
||||
zeroCounter++;
|
||||
}
|
||||
|
||||
arrow = (end % MaxArrow + MaxArrow) % MaxArrow;
|
||||
if (arrow == 0)
|
||||
{
|
||||
zeroCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
return zeroCounter.ToString();
|
||||
}
|
||||
}
|
||||
7
AdventOfCode2026/InputReader.cs
Normal file
7
AdventOfCode2026/InputReader.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace AdventOfCode2026;
|
||||
|
||||
public static class InputReader
|
||||
{
|
||||
private const string BasePath = "../../../Inputs/";
|
||||
public static IEnumerable<string> ReadLines(int day, int partNumber = 1) => File.ReadAllLines($"{BasePath}Day{day}_{partNumber}.txt");
|
||||
}
|
||||
10
AdventOfCode2026/Inputs/Day1_0.txt
Normal file
10
AdventOfCode2026/Inputs/Day1_0.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
4446
AdventOfCode2026/Inputs/Day1_1.txt
Normal file
4446
AdventOfCode2026/Inputs/Day1_1.txt
Normal file
File diff suppressed because it is too large
Load diff
34
AdventOfCode2026/Program.cs
Normal file
34
AdventOfCode2026/Program.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
namespace AdventOfCode2026;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
const int numberOfDays = 12;
|
||||
foreach (var day in Enumerable.Range(1, numberOfDays))
|
||||
{
|
||||
RunDay(day);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunDay(int day)
|
||||
{
|
||||
var solutionText = $"Solution for Day {day.ToString().PadLeft(2, '0')}:";
|
||||
var className = $"Day{day}";
|
||||
var classType = Type.GetType($"AdventOfCode2026.{className}");
|
||||
if (classType == null)
|
||||
{
|
||||
Console.WriteLine($"{solutionText} is not implemented.");
|
||||
return;
|
||||
}
|
||||
var instance = Activator.CreateInstance(classType);
|
||||
if (instance is not Solution solution)
|
||||
{
|
||||
throw new NotImplementedException($"{classType} is not implemented.");
|
||||
}
|
||||
|
||||
Console.WriteLine($"{solutionText}");
|
||||
Console.WriteLine($"\tPart 1: {solution.SolvePart1()}");
|
||||
Console.WriteLine($"\tPart 2: {solution.SolvePart2()}");
|
||||
}
|
||||
}
|
||||
7
AdventOfCode2026/Solution.cs
Normal file
7
AdventOfCode2026/Solution.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace AdventOfCode2026;
|
||||
|
||||
public abstract class Solution
|
||||
{
|
||||
public virtual string SolvePart1() => "Part1 is not solved";
|
||||
public virtual string SolvePart2() => "Part2 is not solved";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue