BlackJack Counting

Back to General discussions forum

ucshadow     2015-03-31 16:36:59

Expected Answer: 21 20 16 18 16 16 19 18 20 17 19 21 21 19 20 Bust 18 19 18 21 18

input data: 21-- T A-- 2 9 9-- 5 J A-- A 7-- 4 A T A-- 9 7-- A A A A 5-- 6 3 9-- 8 7 5-- A A 5-- A 2 6-- A K-- J A-- 4 4 A-- 3 J 7-- 5 6 2 A J-- 7 A-- 4 K 4-- A K-- looks like your program is Wrong! look at number 3 5JA should be 18 and it says that I am wrong and it is 16! and it's wrong with other data too, you should try it please fix, thank you.

smwentum     2015-04-01 03:54:52

The deck contains all cards from 2 to 10 inclusive, which are counted according to their value, also Kings, Queens and Jacks which cost 10 points each and also Aces, which could be counted as 1 or 11 points, whatever is better.

5+j+A= 5+10+1 = 16

How are you getting 18?

Matthew Cole     2015-04-01 06:21:47

@ucshadow:

Looking at your input data, I'm not sure what the '-'characters represent. But smwentum gives you some good advice about handling non-numeric card values. I can assure you the problem checker works fine on all input data sets.

I'll add one more tip: it's easier to process aces separately from all other cards since other cards have fixed values, but aces have two possible values.

My algorithm does some pre-handling and exception handling of the data to ensure it's in a usuable format, then counts the number of aces and the total of all other cards. I'll leave it to you to figure out how to turn that information into the final answer. When you're done, feel free to take a look at my code and compare how we did it. But since this topic is not hidden from people who have not yet solved the problem, I'm reluctant to discuss that code here.

Please login and solve 5 problems to be able to post at forum