-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.py
More file actions
103 lines (68 loc) · 1.91 KB
/
std.py
File metadata and controls
103 lines (68 loc) · 1.91 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3
import math
import random
import collections
def mean(seq):
"Get the mean of a sequence of numbers"
return sum(seq) / len(seq)
def std(seq):
"Get the standard deviation of a sequence of numbers"
mean_ = mean(seq)
length = len(seq)
deviations = []
ret = 0
for i in seq:
deviations.append( (i - mean_) ** 2)
return math.sqrt(sum(deviations) / length)
def deviations(seq):
"Tells you the percentage of numbers x standard deviations away from the mean"
dev = collections.defaultdict(list)
ret = collections.defaultdict(int)
mean_ = mean(seq)
std_ = std(seq)
len_ = len(seq)
for i in seq:
away = math.ceil(abs(i - mean_) / std_ )
dev[away].append(i)
last = []
for i in sorted(dev):
current = last + dev[i]
dev[i] = current
last = current
ret[i] = len(dev[i]) / len_
return dict(dev), dict(ret)
def percWithin(seq, lo=None, hi=None):
"Returns the numbers in the sequence within the range specified"
ret = []
len_ = len(seq)
for i in seq:
if lo is None and hi is None:
ret.append(i)
elif lo is None:
if i <= hi:
ret.append(i)
elif hi is None:
if i >= lo:
ret.append(i)
else:
if lo <= i <= hi:
ret.append(i)
return len(ret) / len_
def shoot(damage, count):
"Fire a Doom hitscan shot"
ret = 0
for i in range(count):
ret += damage * random.randint(1, 3)
return ret
def proj(damage, count):
"Roll for Doom projectile damage"
ret = 0
for i in range(count):
ret += damage * random.randint(1, 8)
return ret
def seqMany(func, amount, *a, **ka):
"Do <func> <amount> times and return the results"
ret = []
for i in range(amount):
ret.append(func(*a, **ka) )
return ret