Skip to content

Instantly share code, notes, and snippets.

@mcs
Created May 19, 2022 21:16
Show Gist options
  • Save mcs/09a940bb2a34f279639b66648545c396 to your computer and use it in GitHub Desktop.
Save mcs/09a940bb2a34f279639b66648545c396 to your computer and use it in GitHub Desktop.
public boolean test(List<Card> cards) {
if (cards == null || isStraightFlush.test(cards)) {
return false;
}
List<Card> sortedCards = cards.stream()
.sorted(Comparator.comparing(Card::suit))
.toList();
int suitsInARow = 1;
Suit lastSuit = null;
for (Card card : sortedCards) {
Suit suit = card.suit();
if (lastSuit != null && lastSuit == suit) {
suitsInARow++;
if (suitsInARow == 5)
return true;
} else {
suitsInARow = 1;
}
lastSuit = suit;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment