-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsefulFunctions.py
71 lines (51 loc) · 1.3 KB
/
UsefulFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 5 14:16:22 2022
@author: Remy
"""
# Imports
import numpy as np
from random import randint
def Normalize(a):
n = np.sum(a)
if n == 0:
return a
return a / n
def Fact(x):
factorial = 1
if x < 0:
factorial = -1
for i in range(1, int(x) + 1):
factorial *= i
return factorial
def C(k, n):
if n < k:
return 0
return Fact(n) / (Fact(k) * Fact(n - k))
def C3(a, b, n):
if n < a or n < b:
return 0
return Fact(n) / (Fact(a) * Fact(b) * Fact(n - a - b))
def A(k, n):
if n < k:
return 0
return Fact(n) / Fact(n - k)
def Lklhd(n, m, k, p):
return C(p, k) * A(p, m) * A(k - p, n - m) / A(k, n)
def Lklhd2(n, m, k, p):
return C(p, k) * C(m - p, n - k) / C(m, n)
def IsProbability(prob):
is_prob = True
for i in prob:
if prob < 0. or prob > 1.:
is_prob = False
return is_prob
def DistributeWires(num_players, hand_size, active_wires):
wires = np.zeros(num_players)
given = 0
while given < active_wires:
randy = randint(0, num_players - 1)
if wires[randy] < hand_size:
wires[randy] += 1
given += 1
return wires