Created
September 18, 2013 09:37
-
-
Save droyad/6606825 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var all = @"// redacted"; | |
| var firstLetters = all | |
| .Split('\n') | |
| .Select(n => n.Trim().ToUpper()) | |
| .Select(n => n.Substring(n.IndexOf(" ") + 1)[0]); | |
| var counts = from l in firstLetters | |
| group l by l into g | |
| select new | |
| { | |
| Letter = g.Key, | |
| Count = g.Count() | |
| }; | |
| var forAll = from a in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| join l in counts on a equals l.Letter into j | |
| from x in j.DefaultIfEmpty() | |
| orderby a | |
| select new | |
| { | |
| Letter = a, | |
| Count = x == null ? 0 : x.Count | |
| }; | |
| forAll.Dump(); | |
| forAll.Sum(x=> x.Count).Dump(); | |
| forAll.Where(x => x.Letter <= 'P').Sum(x=> x.Count).Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment