Skip to content

Commit e2304de

Browse files
author
Stéphane FRACHE
committed
Added AdventOfCode2025 solution, project, and DayOne
1 parent 80209a6 commit e2304de

7 files changed

Lines changed: 5036 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
13+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
15+
<PackageReference Include="Moq" Version="4.20.72" />
16+
<PackageReference Include="NUnit" Version="4.3.2" />
17+
<PackageReference Include="NUnit.Analyzers" Version="4.7.0" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\AdventOfCode.Elves\AdventOfCode.Elves.csproj" />
23+
<ProjectReference Include="..\AdventOfCode2025\AdventOfCode2025.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Using Include="NUnit.Framework" />
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using AdventOfCode.Elves.IOHelpers;
2+
using FluentAssertions;
3+
using Moq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
namespace AdventOfCode2025.Tests
9+
{
10+
internal class DayOneTests
11+
{
12+
[TestCase("R19")]
13+
[TestCase("R29")]
14+
[TestCase("R39")]
15+
[TestCase("R49")]
16+
public void NoHitRotation_Should_Count_0_Hits(string input)
17+
{
18+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
19+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input });
20+
StringBuilder sb = new();
21+
StringWriter sw = new StringWriter(sb);
22+
Console.SetOut(sw);
23+
24+
DayOne dayOne = new DayOne(mockInputHelper.Object);
25+
26+
dayOne.PartTwo();
27+
28+
sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 0");
29+
}
30+
31+
[TestCase("R50")]
32+
public void Going_Up_To_100_Should_Count_1_Hit(string input)
33+
{
34+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
35+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input });
36+
StringBuilder sb = new();
37+
StringWriter sw = new StringWriter(sb);
38+
Console.SetOut(sw);
39+
40+
DayOne dayOne = new DayOne(mockInputHelper.Object);
41+
42+
dayOne.PartTwo();
43+
44+
sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1");
45+
}
46+
47+
[TestCase("L50")]
48+
public void Going_Down_To_0_Should_Count_1_Hit(string input)
49+
{
50+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
51+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input });
52+
StringBuilder sb = new();
53+
StringWriter sw = new StringWriter(sb);
54+
Console.SetOut(sw);
55+
56+
DayOne dayOne = new DayOne(mockInputHelper.Object);
57+
58+
dayOne.PartTwo();
59+
60+
sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1");
61+
}
62+
63+
[TestCase("R29,R21")]
64+
public void Going_Up_To_100_In_Two_Moves_Should_Count_1_Hit(string inputLines)
65+
{
66+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
67+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList());
68+
StringBuilder sb = new();
69+
StringWriter sw = new StringWriter(sb);
70+
Console.SetOut(sw);
71+
72+
DayOne dayOne = new DayOne(mockInputHelper.Object);
73+
74+
dayOne.PartTwo();
75+
76+
sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1");
77+
}
78+
79+
[TestCase("L29,L21")]
80+
public void Going_Down_To_0_In_Two_Moves_Should_Count_1_Hit(string inputLines)
81+
{
82+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
83+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList());
84+
StringBuilder sb = new();
85+
StringWriter sw = new StringWriter(sb);
86+
Console.SetOut(sw);
87+
88+
DayOne dayOne = new DayOne(mockInputHelper.Object);
89+
90+
dayOne.PartTwo();
91+
92+
sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1");
93+
}
94+
95+
[TestCase("R1000", 10)]
96+
[TestCase("R50,R200", 3)]
97+
[TestCase("L50,L200", 3)]
98+
public void Passing_0_Multiple_Times_In_One_Move_Should_Count_All_Hits(string inputLines, int hits)
99+
{
100+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
101+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList());
102+
StringBuilder sb = new();
103+
StringWriter sw = new StringWriter(sb);
104+
Console.SetOut(sw);
105+
106+
DayOne dayOne = new DayOne(mockInputHelper.Object);
107+
108+
dayOne.PartTwo();
109+
110+
sb.ToString().Trim().Should().Be($"Part Two: Number of 0 mid-rotation hits {hits}");
111+
}
112+
113+
[TestCase("L68,L30,R48,L5,R60,L55,L1,L99,R14,L82", 6)]
114+
public void Complex_Cases_Should_Be_Handled_Correctly(string inputLines, int hits)
115+
{
116+
Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>();
117+
mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList());
118+
StringBuilder sb = new();
119+
StringWriter sw = new StringWriter(sb);
120+
Console.SetOut(sw);
121+
122+
DayOne dayOne = new DayOne(mockInputHelper.Object);
123+
124+
dayOne.PartTwo();
125+
126+
sb.ToString().Trim().Should().Be($"Part Two: Number of 0 mid-rotation hits {hits}");
127+
}
128+
}
129+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\AdventOfCode.Elves\AdventOfCode.Elves.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Folder Include="Inputs\" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Update="Inputs\DayOne.txt">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Solution>
2+
<Project Path="../AdventOfCode.Elves/AdventOfCode.Elves.csproj" />
3+
<Project Path="../AdventOfCode2025.Tests/AdventOfCode2025.Tests.csproj" />
4+
<Project Path="AdventOfCode2025.csproj" />
5+
</Solution>

AdventOfCode2025/DayOne.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using AdventOfCode.Elves.IOHelpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
8+
[assembly: InternalsVisibleToAttribute("AdventOfCode2025.Tests")]
9+
namespace AdventOfCode2025
10+
{
11+
internal class DayOne(IPuzzleInputHelper inputHelper)
12+
{
13+
public void PartOne()
14+
{
15+
List<String> lines = inputHelper.GetInputLines("DayOne.txt");
16+
int sum = 50;
17+
int hits = 0;
18+
foreach (string line in lines)
19+
{
20+
int direction = 1;
21+
if (line[0] == 'L') direction = -1;
22+
int value = int.Parse(line.Substring(1));
23+
sum = value * direction + sum;
24+
sum %= 100;
25+
if (sum == 0) hits++;
26+
}
27+
28+
Console.WriteLine($"Part One: Number of 0 hits {hits}");
29+
}
30+
31+
//7851 too high
32+
//7371 too high
33+
//6642 too low
34+
public void PartTwo()
35+
{
36+
List<String> lines = inputHelper.GetInputLines("DayOne.txt");
37+
int sum = 50;
38+
int hits = 0;
39+
40+
bool startedOn0 = false;
41+
foreach (string line in lines)
42+
{
43+
startedOn0 = sum == 0;
44+
int direction = 1;
45+
if (line[0] == 'L') direction = -1;
46+
int value = int.Parse(line.Substring(1));
47+
while (value >= 100)
48+
{
49+
value -= 100;
50+
hits++;
51+
}
52+
if (value == 0) continue;
53+
sum = value * direction + sum;
54+
if (sum < 0)
55+
{
56+
sum += 100;
57+
if (!startedOn0)
58+
{
59+
hits++;
60+
}
61+
}
62+
else if (sum > 99)
63+
{
64+
sum -= 100;
65+
hits++;
66+
}
67+
else if (sum == 0)
68+
{
69+
hits++;
70+
}
71+
}
72+
73+
Console.WriteLine($"Part Two: Number of 0 mid-rotation hits {hits}");
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)