wip day 2
This commit is contained in:
@@ -35,21 +35,18 @@ internal class SecretEntrance : Problem<int, int>
|
||||
foreach (var item in Input)
|
||||
{
|
||||
var vStart = v;
|
||||
var sign = int.Sign(item);
|
||||
var curC = 0;
|
||||
|
||||
v += item;
|
||||
if (item > 0)
|
||||
curC += (int)Math.Floor(v / (float)LOCK_SIZE);
|
||||
c += (int)Math.Floor(v / (float)LOCK_SIZE);
|
||||
else
|
||||
{
|
||||
var d = v / (float)LOCK_SIZE;
|
||||
var fl = Math.Floor(d);
|
||||
curC += (int)Math.Abs(fl) - (vStart == 0 ? 1 : 0);
|
||||
c += (int)Math.Abs(fl) - (vStart == 0 ? 1 : 0);
|
||||
if (fl == d)
|
||||
curC += 1;
|
||||
c += 1;
|
||||
}
|
||||
c += curC;
|
||||
v = v.Mod(LOCK_SIZE);
|
||||
}
|
||||
Part2 = c;
|
||||
|
||||
42
AdventOfCode/Problems/AOC2025/Day2/GiftShop.cs
Normal file
42
AdventOfCode/Problems/AOC2025/Day2/GiftShop.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
|
||||
using ZLinq;
|
||||
|
||||
namespace AdventOfCode.Problems.AOC2025.Day2;
|
||||
|
||||
[ProblemInfo(2025, 2, "Gift Shop")]
|
||||
internal class GiftShop : Problem<long, long>
|
||||
{
|
||||
private IdRange[] _ranges = [];
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static List<long> GetDoubleSequences(IdRange range)
|
||||
{
|
||||
var minDigits = range.Min.DigitCount() / 2;
|
||||
var maxDigits = range.Max.DigitCount() / 2;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void CalculatePart2()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void LoadInput()
|
||||
{
|
||||
var text = ReadInputText("sample.txt");
|
||||
_ranges = text.Split(',')
|
||||
.AsValueEnumerable()
|
||||
.Select(r => r.Split('-').Select(int.Parse))
|
||||
.Select(r => new IdRange(r.First(), r.Last()))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public record IdRange(int Min, int Max);
|
||||
}
|
||||
@@ -34,4 +34,14 @@ public static class ExtraMath
|
||||
{
|
||||
return T.Min(a, b);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,5 @@ public static class Extensions
|
||||
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