Day02 part 1
This commit is contained in:
55
AdventOfCode2017/Day02.cs
Normal file
55
AdventOfCode2017/Day02.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AdventOfCode2017
|
||||
{
|
||||
/*
|
||||
|
||||
--- Day 2: Corruption Checksum ---
|
||||
|
||||
As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"
|
||||
|
||||
The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.
|
||||
|
||||
For example, given the following spreadsheet:
|
||||
|
||||
5 1 9 5
|
||||
7 5 3
|
||||
2 4 6 8
|
||||
|
||||
The first row's largest and smallest values are 9 and 1, and their difference is 8.
|
||||
The second row's largest and smallest values are 7 and 3, and their difference is 4.
|
||||
The third row's difference is 6.
|
||||
|
||||
In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
|
||||
|
||||
What is the checksum for the spreadsheet in your puzzle input?
|
||||
|
||||
*/
|
||||
public class Day02 : IDay
|
||||
{
|
||||
public string ResolvePart1(string[] inputs)
|
||||
{
|
||||
int checksum = 0;
|
||||
foreach(string input in inputs)
|
||||
{
|
||||
int[] row = input
|
||||
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(cell => Convert.ToInt32(cell))
|
||||
.ToArray();
|
||||
int max = row.Max();
|
||||
int min = row.Min();
|
||||
checksum += (max - min);
|
||||
}
|
||||
return checksum.ToString();
|
||||
}
|
||||
|
||||
public string ResolvePart2(string[] inputs)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user