-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamev10_nHr_id_checker.py
82 lines (53 loc) · 1.28 KB
/
gamev10_nHr_id_checker.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
72
73
74
75
76
77
import numpy as np
from itertools import repeat
table = np.fromfile("v9_fevertime_table", np.uint8, -1)
def nCr_precalculated():
pre_calc_table = np.fromfile(
"nCrTable0-31x0-31", np.uint32, -1).reshape([32, 32])
def r_nCr(n, r):
return pre_calc_table[n, r]
return r_nCr
nCr = nCr_precalculated()
def nHr(n: int, r: int):
return nCr((n+r-1), r)
def id_from_hnr(seq):
formatted=np.zeros(16, np.uint8)
for tile in seq:
formatted[tile]+=1
count=10
id=0
ln=15
for loc in range(15, -1, -1):
if formatted[loc]==0:
continue
for _ in repeat(None, formatted[loc]):
count-=1
for s in range(ln+1, loc+1, -1):
id+=nHr(s, count)
ln=loc
return id
def nHr_next(n, r):
arrange = np.full(r, n-1, dtype=np.uint8, order='C')
arrange[-1] = n
def nHr_recursive():
nonlocal arrange
if arrange[0] == 0:
print("SOFTWARN: overloop")
arrange = np.full(r, n-1, dtype=np.uint8, order='C')
arrange[-1] = n
p = r-1
while arrange[p] == 0:
p -= 1
arrange[p] -= 1
for i in range(p+1, r):
arrange[i] = arrange[p]
return arrange
return nHr_recursive
test_next = nHr_next(16, 10)
for i in range(10000000):
tbl = test_next()
# print("------")
# print(tbl, " - ")
if i % 1000 == 0:
print("passed 1000 tests...")
assert(i == id_from_hnr(tbl))