feat: Add day 1

This commit is contained in:
Roman Spring 2025-12-01 13:34:09 +01:00
parent 319a02e0fd
commit 8e8ca67091
8 changed files with 4594 additions and 0 deletions

View 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>

View 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
View 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();
}
}

View 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");
}

View file

@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

File diff suppressed because it is too large Load diff

View 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()}");
}
}

View 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";
}