-
-
Save robhol/f02d62100d9cfcc6403caade1d6e5cc8 to your computer and use it in GitHub Desktop.
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
//Core function providing the general solution for the problem | |
int CalcAll(string ip, Func<int, int> locateOther) => | |
Enumerable.Range(0, ip.Length) | |
.Select(i => (a: ip[i], b: ip[locateOther(i) % ip.Length])) | |
.Where(t => t.a == t.b) | |
.Sum(t => t.a - '0'); | |
//Specific solutions | |
int Calc1(string ip) => CalcAll(ip, i => i + 1); | |
int Calc2(string ip) => CalcAll(ip, i => i + ip.Length / 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment