Skip to content

Instantly share code, notes, and snippets.

@jonschoning
Last active June 30, 2024 16:41
Show Gist options
  • Save jonschoning/f31e6b992e7d40dc178bdba280598db3 to your computer and use it in GitHub Desktop.
Save jonschoning/f31e6b992e7d40dc178bdba280598db3 to your computer and use it in GitHub Desktop.

Revisions

  1. jonschoning revised this gist Jun 30, 2024. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion hypergeom.py
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,7 @@

    # chance for k or more successes, pop: M, succ in pop: n, succ in samp: N
    def hyp(k, M, n, N): return 1 - hypergeom.cdf(k-1, M, n, N)
    hyp(3, 99, 35, 7)
    hyp(3, 99, 35, 7)

    # range succ in pop 35 to 40
    [[n, hyp(3, 99, n, 7)] for n in range(35, 40)]
  2. jonschoning revised this gist Jun 30, 2024. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion hypergeom.py
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,8 @@

    # chance for 3 or more successes, pop: 99, succ in pop: 35, succ in samp: 7
    format(1 - hypergeom.cdf(2, 99, 35, 7), ".1%")
    # 47.7%

    # 47.7%
    # chance for k or more successes, pop: M, succ in pop: n, succ in samp: N
    def hyp(k, M, n, N): return 1 - hypergeom.cdf(k-1, M, n, N)
    hyp(3, 99, 35, 7)
  3. jonschoning revised this gist Jun 30, 2024. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions hypergeom.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import numpy as np
    from scipy.stats import hypergeom

    # chance for 3 or more successes, pop: 99, succ in pop: 35, succ in samp: 7
    format(1 - hypergeom.cdf(2, 99, 35, 7), ".1%")

    # 47.7%
  4. jonschoning created this gist Jun 30, 2024.
    44 changes: 44 additions & 0 deletions docalc.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    function docalc() {
    var deck = $('#ndeck').val();
    var copies = $('#ncopies').val();
    var drawn = $('#ndrawn').val();
    var successes = $('#nsuccesses').val();
    var hyperGeoOutput = '<p>';

    //Chance to draw x or more cards
    if (successes > 0)
    pral = 1 - hyp(successes - 1, drawn, copies, deck);
    else
    pral = 1;
    if (pral < 1e-6)
    pral = 0;
    pral = (100 * pral).toPrecision(3) + '%'
    hyperGeoOutput += '<b>Chance to draw ' + successes + ' or more of the wanted card ' + pral + '</b><br>';

    //Chance to draw x cards
    if (successes > 0) {
    pr = hyp(successes, drawn, copies, deck) - hyp(successes - 1, drawn, copies, deck);
    }
    else
    pr = hyp(0, drawn, copies, deck);
    if (pr < 1e-6)
    pr = 0;
    pr = (100 * pr).toPrecision(3) + '%';
    hyperGeoOutput += 'Chance to draw exactly ' + successes + ' of the wanted card <b>' + pr + '</b><br>';

    //Chance to draw x or less cards
    pram = hyp(successes, drawn, copies, deck);
    if (pram < 1e-6)
    pram = 0;
    pram = (100 * pram).toPrecision(3) + '%';
    hyperGeoOutput += 'Chance to draw ' + successes + ' or less of the wanted card <b>' + pram + '</b><br>';

    //Chance to draw 0 cards
    zero = hyp(0, drawn, copies, deck);
    if (zero < 1e-6)
    zero = 0;
    zero = (100 * zero).toPrecision(3) + '%';
    hyperGeoOutput += 'Chance to draw 0 of the wanted card <b>' + zero + '</b></p>';

    $('#hyperGeoOutput').html(hyperGeoOutput);
    }