Advertisement
cupertinoCSstruggle1

11Sum

Mar 30th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. /**
  2. * Check for an 11-pair in the selected cards.
  3. * @param selectedCards selects a subset of this board. It is list
  4. * of indexes into this board that are searched
  5. * to find an 11-pair.
  6. * @return true if the board entries in selectedCards
  7. * contain an 11-pair; false otherwise.
  8. */
  9. private boolean containsPairSum11(List<Integer> selectedCards) {
  10.  
  11. System.out.println(selectedCards);
  12. /*
  13. The point is to find every possible combination, and see if that combination sums up to
  14. be 11
  15. */
  16. int counter = 0;
  17. int counterOther = 0;
  18. int size = selectedCards.size();
  19.  
  20. while(counter < size) {
  21. while(counterOther < size) {
  22. int sum = cardAt(selectedCards.get(counter)).pointValue() + cardAt(selectedCards.get(counterOther)).pointValue();
  23. System.out.println("Sum = " + sum);
  24. if(sum == 11) {
  25. int card = selectedCards.get(counter);
  26. int cardTwo = selectedCards.get(counterOther);
  27. selectedCards.clear();
  28. selectedCards.add(card);
  29. selectedCards.add(cardTwo);
  30. return true;
  31. }
  32. counterOther++;
  33. }
  34. counter++;
  35. counterOther = counter + 1;
  36. }
  37. return false;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement