Day02 part 2
This commit is contained in:
@@ -18,5 +18,19 @@ namespace AdventOfCode2017.Tests
|
|||||||
|
|
||||||
Assert.AreEqual("18", result);
|
Assert.AreEqual("18", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod()]
|
||||||
|
public void ResolvePart2__Test()
|
||||||
|
{
|
||||||
|
Day02 day02 = new Day02();
|
||||||
|
|
||||||
|
string result = day02.ResolvePart2(new string[] {
|
||||||
|
"5 9 2 8",
|
||||||
|
"9 4 7 3",
|
||||||
|
"3 8 6 5",
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.AreEqual("9", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,30 @@ namespace AdventOfCode2017
|
|||||||
|
|
||||||
What is the checksum for the spreadsheet in your puzzle input?
|
What is the checksum for the spreadsheet in your puzzle input?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
"Great work; looks like we're on the right track after all. Here's a star for your effort." However, the program seems a little worried. Can programs be worried?
|
||||||
|
|
||||||
|
"Based on what we're seeing, it looks like all the User wanted is some information about the evenly divisible values in the spreadsheet. Unfortunately, none of us are equipped for that kind of calculation - most of us specialize in bitwise operations."
|
||||||
|
|
||||||
|
It sounds like the goal is to find the only two numbers in each row where one evenly divides the other - that is, where the result of the division operation is a whole number. They would like you to find those numbers on each line, divide them, and add up each line's result.
|
||||||
|
|
||||||
|
For example, given the following spreadsheet:
|
||||||
|
|
||||||
|
5 9 2 8
|
||||||
|
9 4 7 3
|
||||||
|
3 8 6 5
|
||||||
|
|
||||||
|
In the first row, the only two numbers that evenly divide are 8 and 2; the result of this division is 4.
|
||||||
|
In the second row, the two numbers are 9 and 3; the result is 3.
|
||||||
|
In the third row, the result is 2.
|
||||||
|
|
||||||
|
In this example, the sum of the results would be 4 + 3 + 2 = 9.
|
||||||
|
|
||||||
|
What is the sum of each row's result in your puzzle input?
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Day02 : IDay
|
public class Day02 : IDay
|
||||||
{
|
{
|
||||||
public string ResolvePart1(string[] inputs)
|
public string ResolvePart1(string[] inputs)
|
||||||
@@ -49,7 +72,28 @@ namespace AdventOfCode2017
|
|||||||
|
|
||||||
public string ResolvePart2(string[] inputs)
|
public string ResolvePart2(string[] inputs)
|
||||||
{
|
{
|
||||||
return null;
|
int checksum = 0;
|
||||||
|
foreach (string input in inputs)
|
||||||
|
{
|
||||||
|
int[] row = input
|
||||||
|
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(cell => Convert.ToInt32(cell))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
for (int i = 0; i < (row.Length - 1); i++)
|
||||||
|
{
|
||||||
|
for (int j = i + 1; j < row.Length; j++)
|
||||||
|
{
|
||||||
|
int max = Math.Max(row[i], row[j]);
|
||||||
|
int min = Math.Min(row[i], row[j]);
|
||||||
|
if ((max % min) == 0)
|
||||||
|
{
|
||||||
|
checksum += (max / min);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return checksum.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user