Last active
March 28, 2017 15:04
-
-
Save big-kahuna-burger/3d5910c77a1ca2efa83b3a8f510a3ac6 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
static int Proc(int[] A) | |
{ | |
if (A.Length < 3) | |
{ | |
return A.Length; | |
} | |
var seed = new Tuple<int, int, int, int>(A[0], A[1], 2, 2); | |
return A.Aggregate(seed, | |
(a, b) => | |
{ | |
var x = a.Item1; | |
var y = a.Item2; | |
var curr = a.Item3; | |
var max = a.Item4; | |
if (x == y && b == y && b == x) | |
{ | |
curr = 1; | |
max = Math.Max(curr, max); | |
return new Tuple<int, int, int, int>(x, y, 1, max); | |
} | |
else if (b != x && b != y) | |
{ | |
curr = 2; | |
x = y; | |
y = b; | |
max = Math.Max(curr, max); | |
return new Tuple<int, int, int, int>(x, y, 2, max); | |
} | |
else | |
{ | |
curr++; | |
max = Math.Max(curr, max); | |
return new Tuple<int, int, int, int>(x, y, curr, max); | |
} | |
}, | |
(a) => | |
{ | |
return a.Item4; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment