Last active
October 31, 2015 21:30
-
-
Save orangutanboy/f1ba5edef6a27c6e6299 to your computer and use it in GitHub Desktop.
Answers to Mark Heath's Lunchtime Linq Challenge 2
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 startX = 'C'; | |
var startY = 5; | |
var diagonals = Enumerable.Range(65, 8) | |
.SelectMany(x => Enumerable.Range(1, 8), (x, y) => new { x = (char)x, y }) | |
.Where(coord => | |
((coord.x - startX == coord.y - startY)) | |
|| (startX - coord.x == coord.y - startY) | |
|| (startX - coord.x == coord.y + startY) | |
|| (coord.x - startX == coord.y + startY)) | |
.Select(coord => coord.x.ToString() + coord.y.ToString()) | |
.Except(new[] { startX.ToString() + startY }); |
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
"10,5,0,8,10,1,4,0,10,1". | |
Split(','). | |
Select(int.Parse). | |
OrderBy(s => s). | |
Skip(3). | |
Sum() |
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
"Dog,Cat,Rabbit,Dog,Dog,Lizard,Cat,Cat,Dog,Rabbit,Guinea Pig,Dog". | |
Split(','). | |
GroupBy(s => s). | |
ToDictionary(g => g.Key, g => g.Count()) |
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.Join("", | |
Enumerable.Range(0, Regex.Matches("A5B10CD3", @"\D").Count) | |
.Select(i => Regex.Matches("A5B10CD3", @"[A-Za-z]\d*")[i].Groups[0].Value) | |
.Select(match => new { @char = match[0], count = match.Substring(1) }) | |
.Select(x => new string(x.@char, x.count == "" ? 1 : int.Parse(x.count)))) |
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
"0,6,12,18,24,30,36,42,48,53,58,63,68,72,77,80,84,87,90,92,95,96,98,99,99,100,99,99,98,96,95,92,90,87,84,80,77,72,68,63,58,53,48,42,36,30,24,18,12,6,0,-6,-12,-18,-24,-30,-36,-42,-48,-53,-58,-63,-68,-72,-77,-80,-84,-87,-90,-92,-95,-96,-98,-99,-99,-100,-99,-99,-98,-96,-95,-92,-90,-87,-84,-80,-77,-72,-68,-63,-58,-53,-48,-42,-36,-30,-24,-18,-12,-6". | |
Split(','). | |
Select((s, i) => i % 5 == 4 ? s : null). | |
Where(s => !string.IsNullOrEmpty(s)). | |
Select(int.Parse) |
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
"Yes,Yes,No,Yes,No,Yes,No,No,No,Yes,Yes,Yes,Yes,No,Yes,No,No,Yes,Yes". | |
Split(','). | |
Sum(v => v == "Yes" ? 1 : -1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment