Day01 part 2
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AdventOfCode2017
|
||||
namespace AdventOfCode2017
|
||||
{
|
||||
/*
|
||||
*
|
||||
@@ -31,6 +25,22 @@ namespace AdventOfCode2017
|
||||
|
||||
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
|
||||
@@ -52,7 +62,19 @@ namespace AdventOfCode2017
|
||||
|
||||
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