Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created February 18, 2015 19:55
Show Gist options
  • Save jskeet/2c1db126e424cf58cb69 to your computer and use it in GitHub Desktop.
Save jskeet/2c1db126e424cf58cb69 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Test
{
static void Main()
{
var voterA = new List<int> { 1, 2, 3, 4, 7 };
var voterB = new List<int> { 5, 2, 0, 1 };
var voterC = new List<int> { 10, 1 };
var voters = new List<List<int>> { voterA, voterB, voterC };
var votes = Enumerable.Range(0, voters.Max(v => v.Count))
.Select(index => voters.Sum(v => index < v.Count ? v[index] : 0))
.ToList();
Console.WriteLine(string.Join(", ", votes));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment