2012-04: 4
Work out the probability of getting 4 of a kind (any suit) in a five card hand of poker on the first round (before any card changes).
Also what is the probability of getting a full house (3 of one type and 2 of another)?
Calcola la probabilità di avere 4 carte uguali (di qualsiasi seme), nella prima mano (di 5 carte) del mazzo di carte appena mescolato.
Inoltre qual è la probabilità di fare full, 3 carte uguali e 2 carte uguali?
Soluzione 1
Poker
p=1 ' --- crea il mazzo di carte For i=1 To 4 For j=1 To 13 carta[p]=j p=p+1 EndFor EndFor '--------------------------------------------------------------------------- totali=0 ' --- incrementato da mescola() positivi=0 ' --- incrementato da poker() For x=1 to 10000 mescola() controlla() endfor '--------------------------------------------------------------------------- TextWindow.WriteLine("") TextWindow.ForegroundColor="Yellow" TextWindow.WriteLine(positivi + " su " + totali + " = " + (positivi/totali)) TextWindow.ForegroundColor="Gray" '--------------------------------------------------------------------------- Sub poker positivi=positivi+1 TextWindow.WriteLine("") ' --- visualizza il poker TextWindow.ForegroundColor="Green" TextWindow.Write("POKER: ") For q=1 To 5 TextWindow.Write(carta[q] + " ") endfor TextWindow.WriteLine("") TextWindow.ForegroundColor="Gray" EndSub '--------------------------------------------------------------------------- Sub controlla For i=1 To 13 ' --- nessuna carta valore[i]=0 EndFor For i=1 To 5 ' --- conta le prime 5 carte valore[carta[i]]=valore[carta[i]]+1 EndFor For i=1 To 13 ' --- controlla i contatori if valore[i]=4 Then ' --- se poker... poker() EndIf EndFor EndSub '--------------------------------------------------------------------------- Sub mescola For j=1 To 100 ' --- 100 scambi casuali tra carte a=Math.GetRandomNumber(52) b=Math.GetRandomNumber(52) temp=carta[a] carta[a]=carta[b] carta[b]=temp EndFor totali=totali+1 TextWindow.Write(totali + " ") EndSub '--------------------------------------------------------------------------- Sub visualizza For k=1 To 52 TextWindow.Write(carta[k] + " ") EndFor TextWindow.WriteLine(" ") EndSub
Soluzione 2
Full
p=1 ' --- crea il mazzo di carte For i=1 To 4 For j=1 To 13 carta[p]=j p=p+1 EndFor EndFor '--------------------------------------------------------------------------- totali=0 ' --- incrementato da mescola() positivi=0 ' --- incrementato da full() For x=1 to 10000 mescola() controlla() endfor '--------------------------------------------------------------------------- TextWindow.WriteLine("") TextWindow.ForegroundColor="Yellow" TextWindow.WriteLine(positivi + " su " + totali + " = " + (positivi/totali)) TextWindow.ForegroundColor="Gray" '--------------------------------------------------------------------------- Sub full positivi=positivi+1 TextWindow.WriteLine("") ' --- visualizza il full TextWindow.ForegroundColor="Green" TextWindow.Write("FULL: ") For q=1 To 5 TextWindow.Write(carta[q] + " ") EndFor TextWindow.WriteLine("") TextWindow.ForegroundColor="Gray" EndSub '--------------------------------------------------------------------------- Sub controlla For i=1 To 13 ' --- nessuna carta valore[i]=0 EndFor For i=1 To 5 ' --- conta le prime 5 carte valore[carta[i]]=valore[carta[i]]+1 EndFor TRE=0 DUE=0 For i=1 To 13 ' --- controlla i contatori If valore[i]=3 Then TRE=TRE+1 ElseIf valore[i]=2 Then DUE=DUE+1 EndIf EndFor If TRE=1 And DUE =1 Then ' --- se full... full() EndIf EndSub '--------------------------------------------------------------------------- Sub mescola For j=1 To 100 ' --- 100 scambi casuali tra carte a=Math.GetRandomNumber(52) b=Math.GetRandomNumber(52) temp=carta[a] carta[a]=carta[b] carta[b]=temp EndFor totali=totali+1 TextWindow.Write(totali + " ") EndSub '--------------------------------------------------------------------------- Sub visualizza For k=1 To 52 TextWindow.Write(carta[k] + " ") EndFor TextWindow.WriteLine(" ") EndSub