Advent of Code 2017 Day 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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