Write a function that determines the score of a hand in a standard game of Blackjack 21. The function will receive an array of strings representing the cards that are in the hand of the player. Please return the score of the hand as an integer.
Scoring:
Number cards count as their face values. Royalty count as 10s. An Ace can be either 11 or 1.
Return the score closest to 21. If the score is greater than 21, return the score and say "Busted!".
Test cases:
["A"] ["A", "J"] ["A", "10", "A"] ["5", "3", "7"] ["5", "4", "3", "2", "A", "K"]
Happy coding!
This challenge comes from jodymgustafson on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (3)
Python, with a couple assumptions:
My solution uses
itertools.product
to compute possible variations of Ace counting."closest to 21"? I'm guessing you mean "Closest to 21 without going over. If it's not possible to prevent going over, return the lowest score possible."
Is that correct?