Skip to content

Instantly share code, notes, and snippets.

@jonathanchartrand
Last active July 17, 2018 16:38
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 jonathanchartrand/d52a520db39342df4538e553774cdf0a to your computer and use it in GitHub Desktop.
Save jonathanchartrand/d52a520db39342df4538e553774cdf0a to your computer and use it in GitHub Desktop.
LINQ Challenge #3 - Problem 1
// https://markheath.net/post/linq-challenge-3
"1,2,1,1,0,3,1,0,0,2,4,1,0,0,0,0,2,1,0,3,1,0,0,0,6,1,3,0,0,0"
.Split(',')
.Select(s => int.Parse(s))
.Aggregate(Tuple.Create(0, int.MinValue),
(a, b) => (b == 0 ?
Tuple.Create(a.Item1 + 1, Math.Max(a.Item1 + 1, a.Item2)) :
Tuple.Create(0, a.Item2))
).Item2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment