-
-
Save orangutanboy/5870892 to your computer and use it in GitHub Desktop.
Results for Mark Heath's Linq Challenge http://mark-dot-net.blogspot.co.uk/2013/06/lunchtime-linq-challenge.html
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
foreach (var s in Enumerable.Range(1, 11).Zip("Davis, Clyne, Fonte, Hooiveld, Shaw, Davis, Schneiderlin, Cork, Lallana, Rodriguez, Lambert".Split(new[] { ", " }, StringSplitOptions.None), (num, name) => num + ". " + name)) | |
{ | |
Console.WriteLine(s); | |
} |
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
foreach (var playerNameAge in "Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988" | |
.Split(new[] { "; " }, StringSplitOptions.None) | |
.Select(s => { var splits = s.Split(new[] { ", " }, StringSplitOptions.None); var d = DateTime.Parse(splits[1]); return new { Name = splits[0], DoB = d }; }) | |
.OrderByDescending(p => p.DoB) | |
.Select(p => { var today = DateTime.Today; int age = today.Year - p.DoB.Year; if (p.DoB > today.AddYears(-age)) age--; return p.Name + " (" + age + ")"; })) | |
{ | |
Console.WriteLine(playerNameAge); | |
} |
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
Console.WriteLine(TimeSpan.FromSeconds("4:12,2:43,3:51,4:29,3:24,3:14,4:46,3:25,4:52,3:27" | |
.Split(',') | |
.Select(t => new { minutes = int.Parse(t[0].ToString()), seconds = int.Parse(t.Substring(2)) }) | |
.Sum(t => t.minutes * 60 + t.seconds))); |
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
foreach (var s in (from x in Enumerable.Range(0, 3) | |
from y in Enumerable.Range(0, 3) | |
select x + "," + y)) | |
{ | |
Console.WriteLine(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment