Created
July 17, 2018 17:00
-
-
Save jonathanchartrand/180ccb1ea889d36c62d18e7d146a1905 to your computer and use it in GitHub Desktop.
LINQ Challenge #3 - Problem 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
// https://markheath.net/post/linq-challenge-3 | |
"4♣ 5♦ 6♦ 7♠ 10♥;10♣ Q♥ 10♠ Q♠ 10♦;6♣ 6♥ 6♠ A♠ 6♦;2♣ 3♥ 3♠ 2♠ 2♦;2♣ 3♣ 4♣ 5♠ 6♠".Split(';') | |
// preserve original hand string in Item1, split by hand delimiter (space) and truncate suit character | |
.Select(h => Tuple.Create(h, h.Split(' ').Select(c => c.Substring(0, c.Length - 1)))) | |
// detect a 'full house' by grouping by card value and selecting the count. We only care about counts that are equal to 2 or 3. Those that pass this filter must have a sum of 5. | |
.Where(hs => hs.Item2.GroupBy(h => h).Select(h => h.Count()).Where(h => h == 2 || h == 3).Sum() == 5) | |
// return original hand | |
.Select(h => h.Item1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment