BlackJack Hand
Premium Content - Free Preview
This problem is scored like BlackJack II, but you need to deal with an array of numbers instead of one number:
In general, return the sum of a given list of numbers. If the sum is greater than 21
, return 0
, unless one or more of the numbers is 11
. In such a case, as many 11
's as necessary should be 'converted' to 1
's to prevent the sum from being exceeded.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.
Comments
Lukas Dancak
Mar 17, 7:16 PMHi. Can you help me?
Look at my submission (number 1.).
http://www.learneroo.com/modules/25/nodes/145/submissions
For INPUT is shows OK, but for OTHER INPUT is shows incorrect.
Why?
Learneroo
Mar 17, 7:18 PM@Lukas, the challenge now shows the complete I/O table so you can see what you got wrong.
Lukas Dancak
Mar 17, 7:25 PMthanks, I see it now.
I did think that I can turn 11 to 1 only one time.
Because there is written : "....you should "convert" ONE 11 to 1 and return a.....".
My english is not perfect.
David
Apr 4, 9:23 AMDear Admin,
I believe row 7 is incorrect:
Input is:
11 11 2 11 11 4
How can the correct output be 20 if you are only allowed ONCE to change 11 to 1?
Thanks
Learneroo
Apr 4, 12:12 PM@David, as many 11's as necessary should be converted to 1's to prevent the sum from being exceeded.
Pierre Niau
Jun 12, 7:14 PMIn row 3, how can you change the 11 to 1 if you only know that the sum will exceed 21 after the next draw?
Does this means that you initially count it as an 11 but then, as 10 and 5 appear,
you come back and count it as a 1? I don't know the real rules of the game but sounds like cheating to me. :P
Learneroo
Jun 12, 7:18 PM@Pierre, in this version of Blackjack, the Ace always has the optimal value, regardless of order (your program ensures this!)
I've come up with a solution that is incorrect when I run the code. However when I go into debug, the outputs are all correct. Could this be looked into please?
Learneroo
Jan 29, 9:50 AMYour recent submission prints incorrect numbers such as 14 instead of 16 for the third case.
thales
Jul 19, 8:12 AMA solution:
my code
Bernard Mitchell
Aug 14, 2:20 PMCan I get a hint to what I'm doing wrong with my code? Thanks
Learneroo
Aug 14, 3:42 PMIt looks like you're making it more complicated than necessary. To figure out the score, you just need the total sum and the number of elevens. You can then determine how many (If any) elevens
should be converted to ones. First make sure you can get the correct sum, and then work on adjusting the elevens.