-
-
Save mcs/09a940bb2a34f279639b66648545c396 to your computer and use it in GitHub Desktop.
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
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