-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_array.py
More file actions
70 lines (58 loc) · 1.13 KB
/
gen_array.py
File metadata and controls
70 lines (58 loc) · 1.13 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
from itertools import product
kwds = [
"auto",
"break",
"case",
"char",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extern",
"float",
"for",
"goto",
"if",
"inline",
"int",
"long",
"register",
"restrict",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"void",
"volatile",
"while",
"_Bool",
"_Complex",
"_Imaginary",
]
def get_sum(kw, a, b):
return (a * ord(kw[0]) + b * ord(kw[-1]) + len(kw) - 3 * ord("a")) & 0x7F
hash_vals = set()
array = ["Identifier" for _ in range(128)]
def find_parameters() -> tuple[int, int, int]:
for a, b in product(range(1, 23), repeat=2):
hash_vals.clear()
for kw in kwds:
hash_vals.add(get_sum(kw, a, b))
if len(hash_vals) == len(kwds):
return a, b, max(hash_vals)
a, b, length = find_parameters()
for kw in kwds:
array[get_sum(kw, a, b)] = kw.title()
print(end="[")
for enum in array:
print(enum, end=", ")
print(end="]\n")