Posts
0
Comments
3
Joined
1 wk. ago
Wow thanks for the mini tutorial :)
Reply
C# ( c sharp )
undefined
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();
}
}
}
Reply
Windows + Visual Studio :(
Reply