Please, using C language, not C+or C++. Thanks. Homework 3 Files to submit: card
ID: 3604208 • Letter: P
Question
Please, using C language, not C+or C++. Thanks.
Homework 3 Files to submit: card_prob.c Time it took Matthew to Complete: 20 mins •
One thing I want to emphasize is that in this problem we are finding the actual probability not estimating through simulation. This means no need for random numbers.
All programs must compile without warnings when using the -Wall and -Werror options • Submit only the files requested Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc • Your program must match the output exactly to receive credit. Make sure that all prompts and output match mine exactly. Easiest way to do this is to copy and paste them • All input will be valid unless stated otherwise • Print all real numbers to two decimal places unless otherwise stated • The examples provided in the prompts do not represent all possible input you can receive. • All inputs in the examples in the prompt are underlined You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program • If you have questions please post them on Piazza Restrictions • No global variables are allowed • Your main function may only declare variables, call other functions, and assign
For this example we are assuming
The size of the deck is 10 cards
Are initial hand size is 3.
There are 3 copies of the card we are looking for
X's in the example represent the card we want. O's are other cards
We will mulligan 2 cards
We want to draw the desired card by turn 2
Lines with --------------------- in the probability are steps that don't involve drawing cards
Initial Draw
Probability of not drawing the desired card in the initial draw: 7/10 * 6/9 * 5/8
Mulligan
Probability of not drawing desired card in the mulligan: 4/7 * 3/6
Drawing
Probability of not drawing the card during draw process is 4/7 * 3/6
The probability of not drawing at least 1 copy of the card we are looking for is Probability not drawing in initial hand * Probability not drawing in mulligan * Probability not drawing in during draw process. Filling in our numbers that is
(7/10 * 6/9 * 5/8) * (4/7 * 3/6) * (4/7 * 3/6)
And 1 minus the above is the probability of drawing at least 1 copy of the card by the desired turn
1 - (7/10 * 6/9 * 5/8) * (4/7 * 3/6) * (4/7 * 3/6)
Hand Deck Probability Description XXXOOOOOOO ----------- State at beginning O XXXOOOOOO 7/10 Draw first card OO XXXOOOOO 6/9 Draw second card OOO XXXOOOO 5/8 Draw third cardExplanation / Answer
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
// fCCounter = first choice counter, sCCounter = second choice counter
int counter = 10000, fCCounter = 0, sCCounter = 0;
// I run the simulation 10000 times
for(int i = 0; i <= counter; ++i)
{
// openDoor is one of three doors that is opened to the contestant.
int openDoor = 0;
// randomly select which door is the prize door and the users first choice.
int prizeDoor = (rand()*3)/(1+RAND_MAX);
int firstChoice = (rand()*3)/(1+RAND_MAX);
// If the prizeDoor is the users choice, then randomly
// select the door to be opened by the host.
if(prizeDoor == firstChoice)
{
openDoor = (rand()*2)/(1+RAND_MAX);
if(openDoor == prizeDoor || openDoor == firstChoice)
openDoor++;
}
// Increment counters in accordance to what variable selection is.
int selection = 0;
if(selection == firstChoice)
fCCounter++;
if(selection == openDoor)
sCCounter++;
}
// Display percentages of your chances of staying with your
// original choice or switching over to the remaining door.
cout << "Stay: " << (100*fCCounter)/10000 << endl;
cout << "Change choice: " << (100*sCCounter)/10000 << endl;
return 0;
}