Skip to content

Commit f78a394

Browse files
Merge pull request #31 from MartinZikmund/feature/aoc2025-day5
2 parents 6a5edfa + 888818a commit f78a394

5 files changed

Lines changed: 97 additions & 3 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
namespace AdventOfCode.Puzzles._2025._05.Part1;
3+
4+
public class AoC2025Day5Part1 : IPuzzleSolution
5+
{
6+
public record Interval(ulong Start, ulong End);
7+
8+
public async Task<string> SolveAsync(StreamReader inputReader)
9+
{
10+
var freshIntervals = new List<Interval>();
11+
while (await inputReader.ReadLineAsync() is { } line && !string.IsNullOrEmpty(line))
12+
{
13+
var parts = line.Split("-");
14+
var start = ulong.Parse(parts[0]);
15+
var end = ulong.Parse(parts[1]);
16+
var interval = new Interval((ulong)start, (ulong)end);
17+
freshIntervals.Add(interval);
18+
}
19+
20+
var freshIngredientCount = 0;
21+
while (await inputReader.ReadLineAsync() is { } line)
22+
{
23+
var ingredientNumber = ulong.Parse(line);
24+
var containsIngredient = freshIntervals.Any(interval =>
25+
ingredientNumber >= interval.Start && ingredientNumber <= interval.End);
26+
if (containsIngredient)
27+
{
28+
freshIngredientCount++;
29+
}
30+
}
31+
32+
return freshIngredientCount.ToString();
33+
}
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace AdventOfCode.Puzzles._2025._05.Part2;
2+
3+
public class AoC2025Day5Part2 : IPuzzleSolution
4+
{
5+
public record Interval(ulong Start, ulong End);
6+
7+
public async Task<string> SolveAsync(StreamReader inputReader)
8+
{
9+
var freshIntervals = new List<Interval>();
10+
while (await inputReader.ReadLineAsync() is { } line && !string.IsNullOrEmpty(line))
11+
{
12+
var parts = line.Split("-");
13+
var start = ulong.Parse(parts[0]);
14+
var end = ulong.Parse(parts[1]);
15+
var interval = new Interval((ulong)start, (ulong)end);
16+
freshIntervals.Add(interval);
17+
}
18+
19+
var orderedIntervals = freshIntervals
20+
.OrderBy(i => i.Start)
21+
.ThenBy(i => i.End)
22+
.ToList();
23+
24+
var numberOfFreshIngredients = 0UL;
25+
var currentStart = orderedIntervals[0].Start;
26+
var currentEnd = orderedIntervals[0].End;
27+
foreach (var interval in orderedIntervals.Skip(1))
28+
{
29+
if (interval.End <= currentEnd)
30+
{
31+
continue;
32+
}
33+
34+
if (interval.Start > currentEnd + 1)
35+
{
36+
numberOfFreshIngredients += currentEnd - currentStart + 1;
37+
38+
currentStart = interval.Start;
39+
}
40+
41+
currentEnd = interval.End;
42+
}
43+
44+
numberOfFreshIngredients += currentEnd - currentStart + 1;
45+
46+
return numberOfFreshIngredients.ToString();
47+
}
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
3-5
2+
10-14
3+
16-20
4+
12-18
5+
6+
1
7+
5
8+
8
9+
11
10+
17
11+
32

src/AdventOfCode/Platforms/Desktop/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Uno.UI.Hosting;
12
using Uno.UI.Runtime.Skia;
23

34
namespace AdventOfCode;
@@ -6,12 +7,12 @@ public class Program
67
[STAThread]
78
public static void Main(string[] args)
89
{
9-
var host = SkiaHostBuilder.Create()
10+
var host = UnoPlatformHostBuilder.Create()
1011
.App(() => new App())
1112
.UseX11()
1213
.UseLinuxFrameBuffer()
1314
.UseMacOS()
14-
.UseWindows()
15+
.UseWin32()
1516
.Build();
1617

1718
host.Run();

src/global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
// To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information.
33
"msbuild-sdks": {
4-
"Uno.Sdk": "5.5.49"
4+
"Uno.Sdk": "6.4.42"
55
},
66
"sdk":{
77
"allowPrerelease": true

0 commit comments

Comments
 (0)