Skip to content

Instantly share code, notes, and snippets.

@big-kahuna-burger
Last active March 28, 2017 15:04
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 big-kahuna-burger/3d5910c77a1ca2efa83b3a8f510a3ac6 to your computer and use it in GitHub Desktop.
Save big-kahuna-burger/3d5910c77a1ca2efa83b3a8f510a3ac6 to your computer and use it in GitHub Desktop.
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