Created
October 8, 2013 19:36
-
-
Save misterspeedy/6890274 to your computer and use it in GitHub Desktop.
Utility functions
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
/// True if all cards in the sequence are the same suit. | |
let SameSuit cards = | |
( cards |> Seq.distinctBy (fun card -> card.Suit) |> Seq.length ) = 1 | |
/// True if all the cards in the sequence are consecutive by value. | |
/// Includes both the high-Ace and the low-Ace cases. | |
let Consecutive cards = | |
cards | |
|> Array.map (fun card -> card.Rank) | |
|> Array.sortBy (fun rank -> 0 - rank.SortValue) | |
|> Seq.pairwise | |
|> Seq.map (fun (r1, r2) -> // Handle the low-Ace case: | |
if r1 = Ace && r2 = Value(2) then | |
1 | |
// All other cases including high-Ace: | |
else | |
r1.SortValue - r2.SortValue | |
) | |
|> Seq.filter (fun diff -> diff <> 1) | |
|> Seq.isEmpty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment