Skip to content

Instantly share code, notes, and snippets.

@claraj
Created September 27, 2017 17:18
Show Gist options
  • Save claraj/102bf80e9ca4043dbd2b9a1e0c72b360 to your computer and use it in GitHub Desktop.
Save claraj/102bf80e9ca4043dbd2b9a1e0c72b360 to your computer and use it in GitHub Desktop.
// TODO make books for this hand. Remove cards from the hand, and add one entry to the books list.
// example: hand has 4 "6" values in, so a book of 6s. Remove all "6" from hand, and add one "6" to books.
// example: hand starts as ["6","6","6","2","6","7"], books starts as ["4", "Q"]
// After transfer, hand = ["2","7"] and books = ["4","Q","6"]
// TODO comment your code!!!
ArrayList<String> cardsToRemove = new ArrayList<>();
for (String cardType : hand) {
if (Collections.frequency(hand,cardType) == 4) {
cardsToRemove.add(cardType);
}
}
System.out.println("cards to remove " + cardsToRemove);
if (cardsToRemove.size() > 0) {
for (String c: cardsToRemove) {
if (!books.contains(c)) books.add(c);
}
}
hand.removeAll(cardsToRemove);
System.out.println("books = " + books);
System.out.println("hand = " + hand);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment