Skip to content

Instantly share code, notes, and snippets.

@csuzw
Last active December 3, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csuzw/4689baeaaeef60eb57d7883fe94a3548 to your computer and use it in GitHub Desktop.
Save csuzw/4689baeaaeef60eb57d7883fe94a3548 to your computer and use it in GitHub Desktop.
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