public static class Day3
{
static int r;
static int d;
static string[] input = new string[] { //input };
static Stopwatch timer = new Stopwatch();
static int trees = 0;
public static void Execute()
{
timer.Start();
findNextLocationAndUpdateTreeCount();
}
private static void findNextLocationAndUpdateTreeCount()
{
var line = input[d];
var positionOnLine = line.ToCharArray()[r];
if (positionOnLine == '#')
trees++;
//For part 2 change r and d to the values you have to check
r += 3;
d += 1;
if (input.Length <= d) {
timer.Stop();
Console.WriteLine($"Answer: {trees} trees");
Console.WriteLine($"Executed in: {timer.ElapsedMilliseconds} milliseconds ({timer.ElapsedTicks} Ticks)");
Console.ReadLine();
}
if(line.Length <= r)
{
//By using r - line.Length you don't have to copy the whole input when you reached the end on the right (also possible to use Mod)
r = r - line.Length;
}
findNextLocationAndUpdateTreeCount();
}
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in C#: