Skip to content

Instantly share code, notes, and snippets.

@misterspeedy
Created October 8, 2013 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterspeedy/6890274 to your computer and use it in GitHub Desktop.
Save misterspeedy/6890274 to your computer and use it in GitHub Desktop.
Utility functions
/// 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