π - 2025 DAY 1 SOLUTIONS -π
Day 1: Secret Entrance Megathread guidelines Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever) You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL FAQ What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268 Where do I participate?: https://adventofcode.com/ Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465 You're viewing a single thread.
All Comments
Hot Top New Old Controversial Initials DiceBear https://github.com/dicebear/dicebear https://creativecommons.org/publicdomain/zero/1.0/ βInitialsβ (https://github.com/dicebear/dicebear) by βDiceBearβ, licensed under βCC0 1.0β (https://creativecommons.org/publicdomain/zero/1.0/) GH
ghodawalaaman @programming.dev 4d ago C# ( c sharp )
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApp1
{
public static class Program
{
public static void Part1()
{
var lines = File.ReadAllLines("C:\\Users\\aman\\RiderProjects\\ConsoleApp1\\ConsoleApp1\\input.txt");
var dialReading = 50;
int result = 0;
foreach (var line in lines)
{
if (dialReading == 0)
{
result += 1;
}
char dir = line[0];
int rotation = int.Parse(line.Substring(1));
if (dir == 'R')
{
dialReading += rotation;
dialReading %= 100;
}
else
{
int diff = dialReading - rotation;
if (diff > 0)
{
dialReading -= rotation;
dialReading %= 100;
}
else
{
dialReading = dialReading + 100 - rotation;
dialReading %= 100;
}
}
}
Console.WriteLine(result);
}
public static void Part2()
{
var lines = File.ReadAllLines("C:\\Users\\aman\\RiderProjects\\ConsoleApp1\\ConsoleApp1\\input.txt");
var dialReading = 50;
int result = 0;
foreach (var line in lines)
{
char dir = line[0];
int rotation = int.Parse(line.Substring(1));
if (dir == 'R')
{
while (rotation > 0)
{
if (dialReading == 0)
result += 1;
dialReading += 1;
dialReading %= 100;
rotation -= 1;
}
}
else
{
while (rotation > 0)
{
if (dialReading == 0)
result += 1;
dialReading -= 1;
if ( dialReading < 0)
dialReading += 100;
dialReading %= 100;
rotation -= 1;
}
}
}
Console.WriteLine(result);
}
public static void Main(string[] args)
{
Part1();
Part2();
}
}
}