Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Probabilities of drawing certain cards

by jdporter (Paladin)
on Jan 06, 2023 at 17:33 UTC ( [id://11149384]=perlmeditation: print w/replies, xml ) Need Help??

This shows the probabilities of drawing two specific cards (labeled A and B) in a hand of five cards, from decks of various sizes.

All numbers are percentages.

When the deck contains no 'draw' cards:

Deck sizeA & BA & !BA ^ BA | B
666.716.733.3100.0
747.623.847.695.2
835.726.853.689.3
927.827.855.683.3
1022.227.855.677.8
1118.227.354.572.7
1215.226.553.068.2
1312.825.651.364.1

When the 'A' card causes Draw 1:

Deck sizeA & BA & !BA ^ BA | B
650.00.050.0100.0
741.78.350.091.7
835.714.350.085.7
931.218.850.081.2
1027.822.250.077.8
1125.025.050.075.0
1222.727.350.072.7

The probabilities of other combinations can be derived from those given in this table:

  • A | !B (A or not B - possibly both conditions) is the inverse of A & !B.
  • A ^ !B (A or not B but NOT both conditions) is the inverse of A ^ B.
  • !A & !B (neither A nor B) is the inverse of A | B
  • !A | !B (not A, or not B - possibly both conditions) is the inverse of A & B.
  • !A ^ !B (not A, or not B, but NOT both conditions) is logically the same as A ^ B.

Replies are listed 'Best First'.
Re: Probabilities of drawing certain cards
by LanX (Saint) on Jan 06, 2023 at 18:41 UTC
    just for fun and cool uses for Perl, here the math for the first column

    DB<29> $h = 5 DB<30> sub A_and_B { bk($n-2,$h-2) / bk($n,$h) } DB<31> sub bk { my ($n,$k) = @_; fac($n)/(fac($k)*fac($n-$k)) } DB<32> sub fac { my ($n) =@_; my $f=1; $f*=$_ for 2..$n; $f} DB<33> printf ( "%i %0.3f\n", $n=$_, A_and_B ) for 6..15 6 0.667 7 0.476 8 0.357 9 0.278 10 0.222 11 0.182 12 0.152 13 0.128 14 0.110 15 0.095

    remaining cols left for the interested reader. :) °

    Further reading:

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

    update

    °) spoiler

Re: Probabilities of drawing certain cards
by LanX (Saint) on Jan 06, 2023 at 19:42 UTC
Re: Probabilities of drawing certain cards
by GrandFather (Saint) on Jan 06, 2023 at 21:55 UTC

    And the Perl content is ...?

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      This is a Meditation. It's just me meditating.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://11149384]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found