Card Drawing Simulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mia023
    New Member
    • May 2007
    • 89

    Card Drawing Simulation

    hello there i have trouble understanding this assignment so can any one explain it to me.



    Joe Optimist makes the following claim “If we draw three cards randomly from a standard 52-card deck, we have a greater than 10% chance of having them be of consecutive face values”. (9 7 8) (Q 10 J) (A 3 2) (Q K A) are all considered consecutive face values, but (3 4 6) and (J Q A) do not, independently of the card
    suits. The draws are always made from a full deck, i.e., a card is returned to the deck before the next one is taken.
    One way to verify this claim is to perform a Monte Carlo simulation in which we randomly draw 3 cards from a deck and check whether the cards have 3 consecutive values. If we repeat this experiment a sufficiently large number of times and collect statistics on the number of times we obtain 3 consecutive cards, the ratio of that number to the total number of trials gives us an estimate of the probability we seek.
    Write a program Consecutive.jav a to evaluate whether the claim is true or not. The program should take a command line integer parameter N indicating the number of trials to perform and return the probability of having a 3-draw consisting of consecutive face values. Run the program with N = 1,000, N = 10,000, N=100,000 and comment on the accuracy of your results. Hints: The face values of cards can be mapped to integers between 1 and 13. Write a method that returns a random number in that range, and use it to draw 3 cards. Write another method that checks whether 3 cards have consecutive face values.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mia023
    hello there i have trouble understanding this assignment so can any one explain it to me.



    Joe Optimist makes the following claim “If we draw three cards randomly from a standard 52-card deck, we have a greater than 10% chance of having them be of consecutive face values”. (9 7 8) (Q 10 J) (A 3 2) (Q K A) are all considered consecutive face values, but (3 4 6) and (J Q A) do not, independently of the card
    suits. The draws are always made from a full deck, i.e., a card is returned to the deck before the next one is taken.
    One way to verify this claim is to perform a Monte Carlo simulation in which we randomly draw 3 cards from a deck and check whether the cards have 3 consecutive values. If we repeat this experiment a sufficiently large number of times and collect statistics on the number of times we obtain 3 consecutive cards, the ratio of that number to the total number of trials gives us an estimate of the probability we seek.
    Write a program Consecutive.jav a to evaluate whether the claim is true or not. The program should take a command line integer parameter N indicating the number of trials to perform and return the probability of having a 3-draw consisting of consecutive face values. Run the program with N = 1,000, N = 10,000, N=100,000 and comment on the accuracy of your results. Hints: The face values of cards can be mapped to integers between 1 and 13. Write a method that returns a random number in that range, and use it to draw 3 cards. Write another method that checks whether 3 cards have consecutive face values.
    Why didn't you ask your teacher about it?

    Comment

    • Neverhood
      New Member
      • Nov 2007
      • 3

      #3
      Originally posted by mia023
      hello there i have trouble understanding this assignment so can any one explain it to me.



      Joe Optimist makes the following claim “If we draw three cards randomly from a standard 52-card deck, we have a greater than 10% chance of having them be of consecutive face values”. (9 7 8) (Q 10 J) (A 3 2) (Q K A) are all considered consecutive face values, but (3 4 6) and (J Q A) do not, independently of the card
      suits. The draws are always made from a full deck, i.e., a card is returned to the deck before the next one is taken.
      One way to verify this claim is to perform a Monte Carlo simulation in which we randomly draw 3 cards from a deck and check whether the cards have 3 consecutive values. If we repeat this experiment a sufficiently large number of times and collect statistics on the number of times we obtain 3 consecutive cards, the ratio of that number to the total number of trials gives us an estimate of the probability we seek.
      Write a program Consecutive.jav a to evaluate whether the claim is true or not. The program should take a command line integer parameter N indicating the number of trials to perform and return the probability of having a 3-draw consisting of consecutive face values. Run the program with N = 1,000, N = 10,000, N=100,000 and comment on the accuracy of your results. Hints: The face values of cards can be mapped to integers between 1 and 13. Write a method that returns a random number in that range, and use it to draw 3 cards. Write another method that checks whether 3 cards have consecutive face values.
      The point is to simulate a drawing of cards... Make a method that gives you a random card (maybe think of the random cards as random numbers from 1 to 13). Then make a loop so you get 3 random numbers. Then make some logic that can determine if the numbers are 3 consecutive numbers. For example (1 2 3) but take care that (1 3 2) would also count as consecutive.

      This should get you on your way, but really... if you get an assignment and you have no clue what's going on, then you should talk to your teacher, not a internet forum.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        You can check the outcome of your Monte Carlo simulation: you can draw three
        numbers in the range [1,13] in 13^3 ways. Only 11*3! draws are correct, i.e.
        1-2-3, 2-3-4, 3-4-5 ... 11-12-13 in any order are the correct draws.

        So the probability of having drawn three adjacent numbers == 11*3!/13^3.
        In other words: that optimistic fellow is way too optimistic ;-)

        kind regards,

        Jos

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Come to think of it: this paragraph is not correct:

          Originally posted by assignment
          Hints: The face values of cards can be mapped to integers between 1 and 13. Write a method that returns a random number in that range, and use it to draw 3 cards. Write another method that checks whether 3 cards have consecutive face values.
          For a real deck of cards there's the probability that you draw 3 equal cards, no
          matter the suit is 1x(3*51)x(2*50) .

          The probability to draw three equal numbers out of a set [1,13] equals (1/13)^2

          Those probabilities aren't equal.

          kind regards,

          Jos

          Comment

          • mia023
            New Member
            • May 2007
            • 89

            #6
            Originally posted by JosAH
            Come to think of it: this paragraph is not correct:



            For a real deck of cards there's the probability that you draw 3 equal cards, no
            matter the suit is 1x(3*51)x(2*50) .

            The probability to draw three equal numbers out of a set [1,13] equals (1/13)^2

            Those probabilities aren't equal.

            kind regards,

            Jos
            Thank you alot i figured it out.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by mia023
              Thank you alot i figured it out.
              Was that your own hint or was it present in the original assignment text? If it
              were the latter, go back to your lecturer and tell her/him about it.

              kind regards,

              Jos

              Comment

              • balabaster
                Recognized Expert Contributor
                • Mar 2007
                • 798

                #8
                Originally posted by JosAH
                Was that your own hint or was it present in the original assignment text? If it
                were the latter, go back to your lecturer and tell her/him about it.

                kind regards,

                Jos
                Seems to me that this is a simple mathematical equation of the form nCr where n is the total number of elements in a set and r is the number of items you wish to choose which will give you the total different combinations of elements in a set...in this instance 13C3.

                Subtract from that the number of consecutive combinations found in a set of 13 and divide one into the other giving you the final result. I forget the exact formula...but it has to do with factorial, it should be easy to find on the internet.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by balabaster
                  Seems to me that this is a simple mathematical equation of the form nCr where n is the total number of elements in a set and r is the number of items you wish to choose which will give you the total different combinations of elements in a set...in this instance 13C3.

                  Subtract from that the number of consecutive combinations found in a set of 13 and divide one into the other giving you the final result. I forget the exact formula...but it has to do with factorial, it should be easy to find on the internet.
                  No need to google; see my previous replies for those formula.

                  kind regards,

                  Jos

                  Comment

                  Working...