-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDay01.cs
More file actions
31 lines (28 loc) · 766 Bytes
/
Day01.cs
File metadata and controls
31 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using AdventOfCode.CSharp.Common;
using System;
namespace AdventOfCode.CSharp.Y2015.Solvers;
public class Day01 : ISolver
{
public static void Solve(ReadOnlySpan<byte> input, Solution solution)
{
var currentFloor = 0;
var firstBasementFloor = 0;
for (var i = 0; i < input.Length; i++)
{
if (input[i] == '(')
{
currentFloor++;
}
else
{
currentFloor--;
if (currentFloor == -1 && firstBasementFloor == 0)
{
firstBasementFloor = i + 1;
}
}
}
solution.SubmitPart1(currentFloor);
solution.SubmitPart2(firstBasementFloor);
}
}