Can someone help me write a matlab code that finds probability of full house of
ID: 3670194 • Letter: C
Question
Can someone help me write a matlab code that finds probability of full house of a poker hand this is what I have
function FullHouse
clear all
clc
% Below is a matrix modeling a Deck of Cards.
Deck=['AH';'2H';'3H';'4H';'5H';'6H';'7H';'8H';'9H';'TH';'JH';'KH';'QH';....
'AS';'2S';'3S';'4S';'5S';'6S';'7S';'8S';'9S';'TS';'JS';'KS';'QS';....
'AD';'2D';'3D';'4D';'5D';'6D';'7D';'8D';'9D';'TD';'JD';'KD';'QD';....
'AC';'2C';'3C';'4C';'5C';'6C';'7C';'8C';'9C';'TC';'JC';'KC';'QC'];
% Below is an explanation of a program to the user.
display(' This program simulates The probability of a Full house poker hand. ')
% Prompting the user below
trials=input(' Please enter the number of trials you want to run. ')
% Below we initialize the counter the number of favorable outcomes.
counter = 0;
% Outer loop to determine multiple poker hands.
for i = 1:trials
% Shuffling the deck using the random number generator.
index = randperm(52);
shuffletheDeck = Deck(index);
hand = shuffletheDeck(1:5);
cards = sort(hand);
if (cards(1) == cards(4)) || (cards(2) == cards(5))
counter = counter + 1;
end
end
% Below we determine the frequency of probabality.
p = counter / trials;
fprintf(' The probability of a Full House Poker Hand using %d trials is %d .',trials,p);
Explanation / Answer
You code is fine, only there was one mistake:
if (cards(1) == cards(4)) || (cards(2) == cards(5)) has to be replaced by
if ((cards(1) == cards(3)) && (cards(4) == cards(5)) ) || ((cards(1) == cards(2)) && (cards(3) == cards(5)))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.