Statistics

Problem Statement for "TheBlackJackDivOne"

Problem Statement

John and Brus are training for a card game tournament. There they will be playing Black Jack. Black Jack is played using a standard deck containing 52 distinct cards. Each card can be represented as a two-character string where the first character is the rank ('2' - '9' for ranks Two through Nine, 'T' for Ten, 'J' for Jack, 'Q' for Queen, 'K' for King and 'A' for Ace) and the second character is the suit ('S' for Spades, 'C' for Clubs, 'D' for Diamonds and 'H' for Hearts). For example, the Jack of Spades can be represented as "JS" and the Nine of Hearts as "9H".

Each time a player receives a card from the deck, his score increases by the card's value. Ranks Two through Ten have values of 2 - 10, respectively. Jacks, Queens and Kings each have a value of 10, and Aces have a value of 11.

Brus randomly shuffles the full card deck and gives John one or more cards from the top of the deck. You are given a String[] cards, where each element represents a single card given to John in this initial step. John will then take extra cards from the top of the deck, one by one, until his score is greater than or equal to 21. Return the expected number of extra cards that John will take.

Definition

Class:
TheBlackJackDivOne
Method:
expected
Parameters:
String[]
Returns:
double
Method signature:
double expected(String[] cards)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

  • cards will contain between 1 and 50 elements, inclusive.
  • Each element of cards will contain exactly two characters, where the first character is '2'-'9', 'T', 'J', 'Q', 'K' or 'A', and the second character is 'S', 'C', 'D' or 'H'.
  • All elements of cards will be distinct.

Examples

  1. {"JS"}

    Returns: 2.105854341736695

  2. {"KD", "8S"}

    Returns: 1.08

    John will take the second extra card only if the first one is Two.

  3. {"KD", "2S", "2C", "2D", "2H"}

    Returns: 1.0

    The same situation, but here there are no Twos left in the deck.

  4. {"AS", "KS", "9S", "JC", "2D"}

    Returns: 0.0

    Here John's score is already more than 21.

  5. {"QD", "9C", "KC", "4S", "8S"}

    Returns: 0.0

  6. {"5H", "8D", "4S", "JS", "2H"}

    Returns: 0.0

  7. {"5S", "2S", "AD", "TS", "7S"}

    Returns: 0.0

  8. {"7S", "JS"}

    Returns: 1.16

  9. {"QS", "4C", "8S"}

    Returns: 0.0

  10. {"2D", "7S"}

    Returns: 2.2131458966565347

  11. {"7D"}

    Returns: 2.4521936434148124

  12. {"7S"}

    Returns: 2.4521936434148124

  13. {"2D", "TH"}

    Returns: 1.6197448979591837

  14. {"7S", "6S"}

    Returns: 1.5034693877551022

  15. {"4D"}

    Returns: 2.785899673467907

  16. {"2S"}

    Returns: 3.0307141148164476

  17. {"2S"}

    Returns: 3.0307141148164476

  18. {"2D"}

    Returns: 3.0307141148164476

  19. {"KH"}

    Returns: 2.105854341736695

  20. {"3D"}

    Returns: 2.9085951580755647

  21. {"8S"}

    Returns: 2.3413101410777077

  22. {"5S"}

    Returns: 2.6697214871147352

  23. {"KC"}

    Returns: 2.105854341736695

  24. {"3S"}

    Returns: 2.9085951580755647

  25. {"7C"}

    Returns: 2.4521936434148124

  26. {"2H"}

    Returns: 3.0307141148164476

  27. {"AS", "2S"}

    Returns: 1.5104591836734693

  28. {"2D"}

    Returns: 3.0307141148164476

  29. {"7C"}

    Returns: 2.4521936434148124

  30. {"TS"}

    Returns: 2.105854341736695

  31. {"AD", "9H", "5S", "6D", "AC", "9C", "TS", "2H", "5D", "4S", "TC", "JD", "JC", "6S", "9S", "6H", "QS", "TH", "2S", "KD", "2C", "JH", "4C", "7D", "2D", "7C", "QD", "8C", "3D", "AS", "AH", "4D", "8S", "3H", "8D", "9D", "KC", "TD", "KH", "JS", "KS", "7S", "QH", "8H", "4H", "3S"}

    Returns: 0.0

  32. {"JC", "TH", "8H", "3H", "9S", "7H", "2S", "3C", "2H", "TC", "JH", "JD", "9C", "2D", "TD", "9D", "AD", "8D", "8S", "6S", "6C", "4H", "3S", "7C", "AH", "QH", "KC", "4S", "7S", "4D", "5S", "TS", "KD", "2C", "3D", "5D", "AS", "JS", "KS", "5C", "QD", "4C", "QS", "6D"}

    Returns: 0.0

  33. {"2S", "5H", "JD", "3D", "7H", "5C", "QS", "5D", "3H", "8C", "9S", "QC", "AC", "AH", "6H", "7C", "TD", "9D", "5S", "6D", "TH", "TS", "7D", "JC", "2H", "4H", "4S", "AS", "JH", "9H", "8D", "JS", "6S", "KD", "KS", "3S", "2C", "KH", "AD", "7S", "KC", "4D", "2D", "8S", "QD"}

    Returns: 0.0

  34. {"JH", "QD", "AC", "3C", "KH", "AS", "KC", "4S", "QH", "8S", "AH", "6D", "2D", "7H", "9H", "4D", "TS", "KS", "3H", "5S", "QS", "6H", "2C", "6S", "JS", "JC", "2S", "3S", "9D", "AD", "4C", "QC", "TC", "KD", "3D", "8C", "TH", "7S", "7C", "4H", "9S", "6C", "7D", "JD", "8H", "2H", "8D", "TD", "5D", "9C"}

    Returns: 0.0

  35. {"KD", "9D", "TC", "2D", "QD", "7D", "AD", "3C", "JC", "JS", "5C", "3H", "9C", "AS", "TH", "AH", "5S", "4D", "2C", "QC", "8D", "6S", "2H", "JH", "QS", "3D", "4C", "QH", "7C", "4H", "6D", "9S", "5D", "KC", "6H", "TS", "2S", "KS", "8S", "5H", "AC", "6C", "8H", "JD", "4S", "8C", "7S", "9H", "TD", "3S"}

    Returns: 0.0

  36. {"8C", "4D", "KD", "TD", "9C", "TS", "AC", "5S", "4H", "AD", "TC", "AS", "9S", "3C", "4C", "QS", "8H", "QH", "KH", "5C", "JD", "3S", "3D", "6C", "7C", "KS", "6D", "9H", "6H", "9D", "JS", "AH", "TH", "4S", "QC", "3H", "JC", "7S", "6S", "KC", "QD", "5H", "5D", "8D", "8S", "7D", "2C", "JH", "2H", "7H"}

    Returns: 0.0

  37. {"2C", "4D", "JC", "KS", "8S", "TS", "2D", "5S", "3S", "AD", "4H", "TC", "9S", "3C", "8C", "QS", "JH", "9H", "9D", "5C", "JD", "KC", "3D", "6C", "7C", "AS", "6D", "8H", "4C", "2S", "JS", "7D", "TH", "9C", "QC", "6H", "TD", "7S", "6S", "4S", "KH", "5H", "QH", "8D", "QD", "5D", "KD", "3H", "2H", "7H"}

    Returns: 0.0

  38. {"2D", "2H", "2S", "2C"}

    Returns: 2.2012077294685994

  39. {"2S", "3H", "4S", "5D"}

    Returns: 1.3546677459142769

  40. {"2C", "5S", "4D", "3S"}

    Returns: 1.3546677459142769

  41. {"2D", "4S", "2S", "5D"}

    Returns: 1.451472402096824

  42. {"2S", "5S", "4C", "2D"}

    Returns: 1.451472402096824

  43. {"4C", "3S", "4D", "2S"}

    Returns: 1.4518193031144002

  44. {"2S", "2D", "3C", "2C", "3H", "2H", "3D", "3S"}

    Returns: 1.0

  45. {"2C", "3D", "2S", "3H", "3S", "2H", "2D"}

    Returns: 1.0222222222222221

  46. {"3D", "2C", "2S", "3H", "3S", "3C", "2D"}

    Returns: 1.0222222222222221

  47. {"4D", "4H", "4S", "4C"}

    Returns: 1.1719858156028369

  48. {"JS" }

    Returns: 2.105854341736695

  49. {"2H" }

    Returns: 3.0307141148164476

  50. {"JS", "JC", "JD" }

    Returns: 0.0

  51. {"3S", "3C", "2D", "6H" }

    Returns: 1.3528946962688868

  52. {"KS", "TD", "8S", "9H", "9D" }

    Returns: 0.0

  53. {"AS" }

    Returns: 1.7626450580232094

  54. {"2S", "2C", "2D", "3H", "3D" }

    Returns: 1.5236509404872032

  55. {"2S" }

    Returns: 3.0307141148164476

  56. {"2S", "3D" }

    Returns: 2.6204427747047014

  57. {"2D" }

    Returns: 3.0307141148164476

  58. {"AS", "2S" }

    Returns: 1.5104591836734693

  59. {"TS" }

    Returns: 2.105854341736695

  60. {"QH" }

    Returns: 2.105854341736695

  61. {"AS", "KS", "9S", "JC", "2D" }

    Returns: 0.0

  62. {"9S" }

    Returns: 2.2414622870424763

  63. {"AS", "AD" }

    Returns: 0.0

  64. {"AS", "9H" }

    Returns: 1.0

  65. {"TD", "AD", "2S" }

    Returns: 0.0

  66. {"AS", "TS" }

    Returns: 0.0

  67. {"2S", "2C", "3D" }

    Returns: 2.3517408505184374


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: