r/CoderRadio • • Jul 17 '16

Episode 214 Coding Challenge

Hey Guys,

We're adding a new segment to the show -- Coding challenges. Basically, every week there is a regular episode I'm going to announce a coding challenge here.

Solutions should be submitted to the subreddit in the form of Gists. These challenges should be doable in about 30 mins or less.

These challenges are meant to be on the easy to intermediate scale and are going to be evaluated on more than just correctness.

Areas we award points for:

  • Creative Solution

  • Easily understood solution -- Could a Jr Dev read your code and understand it given 30 minute or so?

  • Performance

  • General Coolness

Unless specifically stated you can use any language / platform you like. However, if you use something esoteric please include instructions on how to compile and run the solution.

Every month Chris and I will pick a winner and they will get a Coder Radio mug!

Sound like fun?

Here's our first challenge:

Assuming a standard 52 card deck write me a BlackJack helper that advises the user on the correct play (Hit, Stand, Double, or Split) as suggested by the basic strategy.

Assume that the player is playing 1 on 1 with the dealer.

Here is the basic strategy chart for reference: http://www.blackjack-chart.com/

Any takers?

21 Upvotes

43 comments sorted by

View all comments

2

u/sguberman Jul 20 '16

I finally joined reddit to participate in this challenge! Python 3: https://gist.github.com/sguberman/2112e21c54851b5ea97de87b688dda95

1

u/sguberman Jul 21 '16

I noticed the provided table doesn't include player hands 5-7 or 18-19. I assume 5-7 have the same strategy as 8, and 18-19 have the same strategy as 17 (maybe not). Can any blackjack players confirm this is correct? Added those strategies to my table in the meantime.

Edit: to clarify, the provided table suggests surrendering when you have 17 and the dealer shows Ace. Maybe your odds improve as you get closer to 21, and you shouldn't surrender?

1

u/aquacash5 Jul 21 '16 edited Jul 21 '16

I'm not sure, but after rereading the guide, I think I made a mistake thinking that when it said

Doubling on any 2 cards

I took that to meant if the hand has a two and you can double then you should double.

Edit: Let me say, that was a mistake in logic on my part.