Day01: Add code to pass tests.

This commit is contained in:
2018-12-03 13:54:38 +01:00
parent 0e16d3f72f
commit ceb8132728

View File

@@ -1,6 +1,4 @@
using System; namespace AdventOfCode2018
namespace AdventOfCode2018
{ {
/* /*
--- Day 1: Chronal Calibration --- --- Day 1: Chronal Calibration ---
@@ -33,12 +31,28 @@ namespace AdventOfCode2018
Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied? Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?
*/ */
public class Day01 public class Day01
{ {
public string ResolveDay01(string[] inputs) public string ResolveDay01(string[] inputs)
{ {
throw new NotImplementedException(); int accumulator = 0;
foreach (string input in inputs)
{
int intInput;
if (int.TryParse(input.Substring(1), out intInput))
{
if (input[0] == '-')
{
accumulator -= intInput;
}
if (input[0] == '+')
{
accumulator += intInput;
}
}
}
return accumulator.ToString();
} }
} }
} }