Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Advent of Code 2017 Day 2
int CorruptionChecksumPartOne(int[][] input)
{
return input.Sum(r =>
{
(var max, var min) = r.Aggregate((max: int.MinValue, min: int.MaxValue), (acc, i) => (i > acc.max ? i : acc.max, i < acc.min ? i : acc.min));
return max - min;
});
}
int CorruptionChecksumPartTwo(int[][] input)
{
return input.Sum(r =>
{
(var hi, var lo) = r.Pairs().First(i => (i.hi % i.lo) == 0);
return hi / lo;
});
}
public static class Extensions
{
public static IEnumerable<(int hi, int lo)> Pairs(this int[] array)
{
foreach (var i in array)
{
foreach (var j in array)
{
if (i > j) yield return (i, j);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment