macro Chances as float(r, n,p)
==============================
'n nomber of opportunities or trials
'p probability of a single coincidence
float np=1.0-p
r=pow(np,n)
r=1.0-r
end macro
'
'TEST
'going to a party with 50 guests.
'what is the chances that someone at the
'party has the same birthday as you?
print str(chances(50, 1/365)*100,0) "%" '13%
'also
print str(chances(300, 1/365)*100,0) "%" '56%
I asked Copilot, and it told me that if I and 49 other people are invited to the same party, the probability that there is another person with the same birthday as mine is 12.5%.
It is 1 - (the probability of not having the same birthday as any single person) ^ 49
1.0 - pow( (364/365), 49)
💪
Here is another:
8 snooker balls are contained in a bag. Only 3 balls are colored red. What is the probability that when you randomly pick 3 balls out of the bag, they are all red?
Charles,
I can't apply your macro to solve this problem
Then just don't go to that party. ;D
Send Jose instead.
Quote8 snooker balls are contained in a bag. Only 3 balls are colored red. What is the probability that when you randomly pick 3 balls out of the bag, they are all red?
No, the macro does not fit the task.
One solution:
(3/8) * (2/7) * (1/6) =
1/56
:o
factorials can also be used to solve this problem:
( 3! * 5! ) / 8!
which expands to:
( 2 * 3 * 2 * 3 * 4 * 5 ) / ( 2 * 3 * 4 * 5 * 6 * 7 * 8 )
which reduces to:
1/( 7*8 )
1 / 56
Hi,
combinations of n items chosen k at a time
'Le combinazioni rispondono a questa domanda:
'In quanti modi posso scegliere k elementi da un insieme di n elementi, senza ordine e senza ripetizione?
'
'Esempio classico:
'"Quanti gruppi da 3 persone posso formare con 8 persone?"
'Qui l'ordine non conta:
'il gruppo (A,B,C) è lo stesso di (C,B,A).
'---------------------------------------------------------------
' Calcola le combinazioni C(n, k) come float
function Comb(n as int, k as int) as double
int i, kk
double num = 1.0
double den = 1.0
' Symmetry: C(n,k) = C(n,n-k)
kk = k
if kk > n - kk then kk = n - kk
if kk < 0 or kk > n then
return 0
elseif kk = 0 or kk = n then
return 1
end if
for i = 1 to kk
num *= (n - kk + i)
den *= i
next
return num / den
end function
'nel caso ci sono 3 palline rosse in un gruppo di 8 palline
'la probabilità che si riesca a pescare 3 palline tutte rosse
'viene calcolata
float num, den
num=Comb(3, 3) 'c'è un solo modo per prendere tutte e 3 rosse
den=Comb(8, 3) ' 56 è il numero delle cominazione totali a 3 a 3
double p = num/den * 100
print "P(all red) = " p
The next challenge:
As before there are 3 red balls in a bag of 8.
What is the probability of picking 3 balls and none of them are red?