Alex Rivera | Logout

Implementation of a simple algorithm (to calculate probability)

Asked 2009-12-15T19:55:25.183
14

I've been asked (as part of homework) to design a Java program that does the following:


Basically there are 3 cards:

  • Black coloured on both sides
  • Red coloured on both sides
  • Black on one side, red on the other side

Now if I take a card randomly and place it on the table. The side facing up is black. What is the probability that the other side is also black?

Implement a program using Java and try to discover the probability, the program should simulate the card trick a large number of times and should output the probability that the other side of the card is black (it does this by counting how many times the other side also black).


However I've been told that my code is wrong (algorithm wise)... apparently the answer should not be 0.50. Have I made a mistake in trying to understand the algorithm?

Can anyone point me in the right direction please? (I'm not asking you to provide me with a fully working implementation, just on how the algorithm should work).


This article was very helpful: https://blog.codinghorror.com/finishing-the-game/

Edit
Report

1 Answer

4

There are six sides to the cards, and we will assume them to come up with equal probability. There are three black faces, and two of them have black on the other side. We discard all cases in which a red face is uppermost, so we're only concerned with three black faces, of equal probability.

Therefore, the probability that the other face is black is in fact 2/3.

answered 2009-12-15T20:02:36.590

Your Answer