Aoc 2025 day 1
This commit is contained in:
@@ -76,6 +76,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
<PackageReference Include="MaybeError" Version="1.2.0" />
|
||||||
|
<PackageReference Include="Superpower" Version="3.1.1-dev-00257" />
|
||||||
|
<PackageReference Include="ZLinq" Version="1.5.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
61
AdventOfCode/Problems/AOC2025/Day1/SecretEntrance.cs
Normal file
61
AdventOfCode/Problems/AOC2025/Day1/SecretEntrance.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ZLinq;
|
||||||
|
|
||||||
|
namespace AdventOfCode.Problems.AOC2025.Day1;
|
||||||
|
|
||||||
|
[ProblemInfo(2025, 1, "Secret Entrance")]
|
||||||
|
internal class SecretEntrance : Problem<int, int>
|
||||||
|
{
|
||||||
|
public int[] Input { get; set; } = [];
|
||||||
|
public override void CalculatePart1()
|
||||||
|
{
|
||||||
|
var c = 0;
|
||||||
|
var v = 50;
|
||||||
|
foreach (var item in Input)
|
||||||
|
{
|
||||||
|
v += item;
|
||||||
|
v = v.Mod(100);
|
||||||
|
if (v == 0)
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
Part1 = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CalculatePart2()
|
||||||
|
{
|
||||||
|
var c = 0;
|
||||||
|
var v = 50;
|
||||||
|
foreach (var item in Input)
|
||||||
|
{
|
||||||
|
var sign = int.Sign(item);
|
||||||
|
for (int i = 0; i < Math.Abs(item); i++)
|
||||||
|
{
|
||||||
|
v += sign;
|
||||||
|
v = v.Mod(100);
|
||||||
|
if (v == 0)
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Part2 = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadInput()
|
||||||
|
{
|
||||||
|
Input = ReadInputLines("input.txt")
|
||||||
|
.AsValueEnumerable()
|
||||||
|
.Select(l =>
|
||||||
|
{
|
||||||
|
return l[0] switch
|
||||||
|
{
|
||||||
|
'L' => -int.Parse(l[1..]),
|
||||||
|
'R' => int.Parse(l[1..]),
|
||||||
|
_ => throw new NotImplementedException()
|
||||||
|
};
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AdventOfCode.Utils;
|
namespace AdventOfCode.Utils;
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static string AsJoinedString<T>(this IEnumerable<T> data, string delim = ", ")
|
public static string AsJoinedString<T>(this IEnumerable<T> data, string delim = ", ")
|
||||||
{
|
{
|
||||||
return string.Join(delim, data);
|
return string.Join(delim, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T Mod<T>(this T value, T divisor) where T : INumber<T>
|
||||||
|
{
|
||||||
|
T remainder = value % divisor;
|
||||||
|
|
||||||
|
if (remainder < T.Zero)
|
||||||
|
return remainder + divisor;
|
||||||
|
else
|
||||||
|
return remainder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user