I am writing a program that deals with cards and a hand. A hand has 5 cards. I want to know whats a good algorithm for deciding which combination of cards add up to 15. Kings, Queens, Jacks, count as 10 and a Ace count as one.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is very similar to subset sums, which I recently answered here: Subset Sum algorithm
The only tweak you need to make is to keep track of which card was used to get from
possible[i]topossible[i+n]. You can keep track of these using a second array let’s call itcard_usedand then setcard_used[i+n]to a reference/index of the card used to get fromitoi+n. Then at the end, you can retrieve the list of cards used to get to the sum of 15 (assumingpossible[15]is true) by backtracking through the listcard_used.