Last active
December 19, 2015 00:59
-
-
Save bruinbrown/5872777 to your computer and use it in GitHub Desktop.
Decided to give Mark Heath's lunchtime LINQ challenge a go. 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
var data = "Davis, Clyne, Fonte, Hooiveld, Shaw, Davis, Schneiderlin, Cork, Lallana, Rodriguez, Lambert"; | |
var result = data.Split(',').Select((str, index) => String.Format("{0}. {1}", index+1, str.Trim())); |
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
string data = "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"; | |
var results = from i in data.Split(';') | |
let split = i.Split(',') | |
let timeDiff = DateTime.Now - DateTime.Parse(split[1].Trim(), new CultureInfo("en-GB")) | |
let age = DateTime.Now.Year - DateTime.Parse(split[1].Trim(), new CultureInfo("en-GB")).Year | |
orderby timeDiff | |
select String.Format("{0} {1}", split[0].Trim(), age); |
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
var data = "4:12,2:43,3:51,4:29,3:24,3:14,4:46,3:25,4:52,3:27"; | |
var timeTotal = (from a in data.Split(',') | |
select TimeSpan.Parse("0:" + a)).Sum(x => x.TotalSeconds); |
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
var points = from i in Enumerable.Range(0, 3) | |
from j in Enumerable.Range(0, 3) | |
select String.Format("{0}, {1}", i, j); |
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
var data = "00:45,01:32,02:18,03:01,03:44,04:31,05:19,06:01,06:47,07:35".Split(','); | |
var results = | |
data.Select(x => new TimeSpan(0, int.Parse(x.Split(':')[0]), int.Parse(x.Split(':')[1]))) | |
.Select( | |
(current, index) => | |
String.Format("{0}", current - (index > 0 ? TimeSpan.Parse("0:" + data[index - 1]) : new TimeSpan()))); |
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
var data = "2,5,7-10,11,17-18"; | |
var results = data.Split(',').SelectMany(x => Regex.IsMatch(x, @"\d-\d") | |
? (Enumerable.Range(int.Parse(x.Split('-')[0]), | |
int.Parse(x.Split('-')[1]) - | |
int.Parse(x.Split('-')[0]) + 1)) | |
: new[] {int.Parse(x)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment