Statistics

Problem Statement for "TwoCardsDraw"

Problem Statement

You have several cards, each with a number printed on them, given in int[] cards. You select two cards--with replacement--from the deck. You then concatenate the values together to form a single value. For example, if you first selected 5 and then 13, your concatenated value would be 513.

What is the probability that the value is prime?

Definition

Class:
TwoCardsDraw
Method:
primeChance
Parameters:
int[]
Returns:
double
Method signature:
double primeChance(int[] cards)
(be sure your method is public)

Notes

  • No leading zeroes are added when concatenating the numbers.

Constraints

  • cards will contain between 1 and 50 elements, inclusive.
  • Each element of cards will be between 1 and 99, inclusive.

Examples

  1. { 1 }

    Returns: 1.0

    The only number you're going to get after concatenation is 11, so it's definitely prime.

  2. { 1, 3 }

    Returns: 0.75

    11, 13, and 31 are prime, but 33 is not.

  3. { 2, 4 }

    Returns: 0.0

    No number you get will be prime.

  4. { 11, 12, 13 }

    Returns: 0.1111111111111111

  5. { 1, 1, 3 }

    Returns: 0.8888888888888888

    Notice that numbers can be repeated.

  6. {1, 1, 3, 9, 20, 1, 7, 22, 39, 4, 50, 20, 30, 40, 99, 45 }

    Returns: 0.2578125

  7. {3, 10, 23, 3, 4, 5, 2, 1, 2, 2, 10, 23, 1 }

    Returns: 0.2603550295857988

  8. {1, 1, 3, 9, 20, 1, 7, 22, 39, 4, 50, 20, 30, 40, 99, 45, 32, 21, 23, 43, 5, 43, 32, 32, 12, 32, 43, 32, 43, 32, 21, 43, 54, 32, 32, 32, 43, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 6, 7 }

    Returns: 0.1704


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: