Skip to content

Instantly share code, notes, and snippets.

@csuzw
Last active Dec 3, 2017
Embed
What would you like to do?
Advent of Code 2017 Day 1
int InverseCaptchPartOne(string input)
{
return DoInverseCaptcha(input, _ => 1);
}
int InverseCaptchPartTwo(string input)
{
return DoInverseCaptcha(input, x => x.Length / 2);
}
int DoInverseCaptcha(string input, Func<int[], int> rotateBy)
{
var x = input.Cast<char>().Select(c => c - 48).ToArray();
return x.Zip(x.Skip(rotateBy(x)).Concat(x.Take(rotateBy(x))), (i, j) => i == j ? i : 0).Sum();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment