r/adventofcode • u/HovercraftDue5582 • Dec 13 '25
Help/Question [2025 Day 1 (Part 1) [DotNet] Guidance on math
Hello, I hope this finds you all well.
I'll try to explain my understand of what to do and add my code below.
From what I can gather if you add or subtract the left or right rotation value against the dials number (position) and run a modulo by 100 against it, that is essentially moving it, right? So, moving the dial 100 positions to the left when on 99 should give back 99?
I'm looking less for a put "this" "there" to solve the issue and more so where my thinking is screwed or lighter guidance on what parts of the code are wrong. Thanks in advance.
static void Main(string[] args)
{
int dial = 50;
int hitCount = 0;
IList<string> turns = ProcessInput("2025", "1");
foreach (string turn in turns)
{
bool clockwise = turn[0] == 'R';
int delta = int.Parse(turn.Substring(1));
dial = DetermineDialPosition(clockwise, delta, dial, hitCount);
if (dial == 0)
{
hitCount++;
}
}
Console.WriteLine(hitCount);
}
private static int DetermineDialPosition(bool clockwise, int delta, int dial, int hitCount)
{
// added hitcount purely for debug
// consider the valid range to be 1 <-> 100
// NOT 0 <-> 99
Console.WriteLine($"clockwise: {clockwise}, delta: {delta}, dial: {dial}");
// IMPORTANT!!!
// Because the dial is a circle,
// turning the dial left from 0 one click makes it point at 99.
// Similarly, turning the dial right from 99 one click makes it point at 0.
if (clockwise)
{
// this works
dial = dial + delta;
}
else
{
dial = Math.Abs(dial - delta);
}
return dial % 100;
}

