English subtitles

← Jokers Wild - Design of Computer Programs

Get Embed Code
1 Language

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. [Norvig] There's an old saying that there's a joker in every deck.
  2. In this exercise we're going to allow for jokers.
  3. In fact, we're going to have 2 kinds of jokers.
  4. There's going to be a black joker and a red joker.
  5. The idea is that if you have a joker as one of the cards in your hand
  6. you can replace it with any other card of the same color.
  7. So if you get the black joker, you can replace it with any spade or club of any rank,
  8. and the red joker, you can replace it with any heart or diamond of any rank.
  9. And what you're asked to do is write a function, bestwildhand(hand),
  10. that tries all possibilities for jokers and comes up with the best 5-card selection.
  11. Like before, hand might be more than 5 cards--it could be 7 cards--
  12. and you still have to come up with the best 5-card answer that substitutes in
  13. one of the appropriate cards for any jokers that exist in the hand.
  14. Here are some tests.
  15. This test says here's a hand where we're doing pretty good.
  16. We already have a straight--6, 7, 8, 9, T--but we also have a wild card,
  17. and we can use that wild card, that joker, and replace it with a jack rather than a 10,
  18. and now we get a slightly higher straight.
  19. We have a straight with a jack high rather than a 10 high.
  20. Here's an example where we have two 10s but we have 2 wild cards,
  21. so we can add in 10s for both of them, and we end up with four 10s, four of a kind.
  22. And here's an example where we show that even if there aren't any jokers
  23. we still come up with the right answer.
  24. And I should say that the hint still holds--that itertools is still your friend.