This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function p = compare_binomial(x1, n1, x2, n2) | |
% Compute P(Beta(x1+1,n1-x1+1) > Beta(x2+1,n2-x2+1)). | |
% Compute p(x1, n1, x2, x2). | |
p = 1; | |
for k = 0:x2 | |
p = p * (x1 + 1 + k) / (n1 + 2 + k); | |
end | |
% Iterate Bayes updates with each of n2 - x2 failures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Compute probability of given subset of horses scratching. *) | |
scratch[p_] := Module[ | |
{done = 2^Length[p] - 1, q, k}, | |
q[0] /. Solve[ | |
Table[ | |
q[k] == If[k == done, 1, | |
Total@MapIndexed[ | |
#1 q[BitOr[k, 2^(#2[[1]] - 1)]] &, | |
p | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3+(6+(22-16/2)) | |
3+(22+(6-16/2)) | |
3+(22-16/(2+6)) | |
3+(22-16/(6+2)) | |
6+(3+(22-16/2)) | |
6-(16-3/(2/22)) | |
6-(16-3*22/2) | |
6-(16-22/(2/3)) | |
6-(16-22*3/2) | |
6+(22+(3-16/2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://possiblywrong.wordpress.com/2015/02/08/searching-for-chocolates/ | |
#include "math_Rational.h" // https://github.com/possibly-wrong/precision | |
#include <vector> | |
#include <map> | |
#include <iterator> | |
#include <algorithm> | |
#include <numeric> | |
#include <iostream> | |
#include <ctime> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* https://possiblywrong.wordpress.com/2015/02/08/searching-for-chocolates/ *) | |
d[n_, k_] := If[! (0 <= k <= n), 0, | |
Sum[ | |
(-1)^j Binomial[k, j] (n - j)!, | |
{j, 0, k} | |
] | |
] | |
v[n_, k_] := v[n, k] = Which[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Ref: https://gist.github.com/skeeto/1718d6613dc47a7aff13333942a40776 | |
*/ | |
static long long | |
valid(long long x) | |
{ | |
int v = 0; | |
long long a = transpose(x); | |
v += x == a; | |
a = flipv(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def sample(): | |
"""Return number of random Skittles packs opened until first duplicate.""" | |
packs = set() | |
count = 0 | |
while len(packs) == count: | |
packs.add(tuple(np.bincount( | |
np.random.randint(0, 5, np.random.binomial(100, 0.6))))) | |
count = count + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 [1] | |
2 [1, 2] | |
3 [1] | |
4 [3] | |
5 [] | |
6 [] | |
7 [] | |
8 [6] | |
9 [] | |
10 [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
units = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', | |
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', | |
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] | |
tens = ['zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', | |
'seventy', 'eighty', 'ninety'] | |
powers = ['zero', 'thousand', 'million', 'billion', 'trillion', | |
'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', | |
'nonillion', 'decillion'] | |
hundred = 'hundred' | |
minus = 'minus' |
NewerOlder