Day01 part 2
This commit is contained in:
@@ -1,16 +1,12 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using AdventOfCode2017;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2017.Tests
|
namespace AdventOfCode2017.Tests
|
||||||
{
|
{
|
||||||
[TestClass()]
|
[TestClass()]
|
||||||
public class Day01_Tests
|
public class Day01_Tests
|
||||||
{
|
{
|
||||||
|
#region ResolvePart1
|
||||||
|
|
||||||
[TestMethod()]
|
[TestMethod()]
|
||||||
public void ResolvePart1__Test1()
|
public void ResolvePart1__Test1()
|
||||||
{
|
{
|
||||||
@@ -50,5 +46,61 @@ namespace AdventOfCode2017.Tests
|
|||||||
|
|
||||||
Assert.AreEqual("9", result);
|
Assert.AreEqual("9", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion ResolvePart1
|
||||||
|
|
||||||
|
#region ResolvePart2
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test1()
|
||||||
|
{
|
||||||
|
Day01 day01 = new Day01();
|
||||||
|
|
||||||
|
string result = day01.ResolvePart2(new string[] { "1212", });
|
||||||
|
|
||||||
|
Assert.AreEqual("6", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test2()
|
||||||
|
{
|
||||||
|
Day01 day01 = new Day01();
|
||||||
|
|
||||||
|
string result = day01.ResolvePart2(new string[] { "1221", });
|
||||||
|
|
||||||
|
Assert.AreEqual("0", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test3()
|
||||||
|
{
|
||||||
|
Day01 day01 = new Day01();
|
||||||
|
|
||||||
|
string result = day01.ResolvePart2(new string[] { "123425", });
|
||||||
|
|
||||||
|
Assert.AreEqual("4", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test4()
|
||||||
|
{
|
||||||
|
Day01 day01 = new Day01();
|
||||||
|
|
||||||
|
string result = day01.ResolvePart2(new string[] { "123123", });
|
||||||
|
|
||||||
|
Assert.AreEqual("12", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test5()
|
||||||
|
{
|
||||||
|
Day01 day01 = new Day01();
|
||||||
|
|
||||||
|
string result = day01.ResolvePart2(new string[] { "12131415", });
|
||||||
|
|
||||||
|
Assert.AreEqual("4", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion ResolvePart2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AdventOfCode2017
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AdventOfCode2017
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@@ -31,6 +25,22 @@ namespace AdventOfCode2017
|
|||||||
|
|
||||||
What is the solution to your captcha?
|
What is the solution to your captcha?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
You notice a progress bar that jumps to 50% completion. Apparently, the door isn't yet satisfied, but it did emit a star as encouragement. The instructions change:
|
||||||
|
|
||||||
|
Now, instead of considering the next digit, it wants you to consider the digit halfway around the circular list. That is, if your list contains 10 items, only include a digit in your sum if the digit 10/2 = 5 steps forward matches it. Fortunately, your list has an even number of elements.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
|
||||||
|
1221 produces 0, because every comparison is between a 1 and a 2.
|
||||||
|
123425 produces 4, because both 2s match each other, but no other digit has a match.
|
||||||
|
123123 produces 12.
|
||||||
|
12131415 produces 4.
|
||||||
|
|
||||||
|
What is the solution to your new captcha?
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Day01 : IDay
|
public class Day01 : IDay
|
||||||
@@ -52,7 +62,19 @@ namespace AdventOfCode2017
|
|||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
return null;
|
string input = inputs[0];
|
||||||
|
int value = 0;
|
||||||
|
int inputLength = input.Length;
|
||||||
|
int inputHalfLength = inputLength / 2;
|
||||||
|
for (int i = 0; i < inputLength; i++)
|
||||||
|
{
|
||||||
|
int nextI = (i + inputHalfLength) % inputLength;
|
||||||
|
if (input[i] == input[nextI])
|
||||||
|
{
|
||||||
|
value += (input[i] - '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user