-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.py
executable file
·96 lines (73 loc) · 2.2 KB
/
inputs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
from collections import Counter
from pathlib import Path
import tabulate
RED = "\033[91m"
GREEN = "\033[92m"
BLUE = "\033[94m"
DARK_GREEN = "\033[32m"
GRAY = "\033[37m"
MAGENTA = "\033[95m"
CYAN = "\033[96m"
WHITE = "\033[97m"
YELLOW = "\033[93m"
RESET = "\033[0m"
FEINT = "\033[2m"
ITALIC = "\033[3m"
BLINK = "\033[6m"
CLEAR_EOL = "\033[0K"
def transpose(m):
rows = range(len(m))
cols = range(len(m[0]))
t = [[None for _ in rows] for _ in cols]
for row in rows:
for col in cols:
t[col][row] = m[row][col]
return t
datadir = Path(__file__).parent.parent / "data"
t = []
for year in range(2015, 2025):
values = []
min_inputs = float("inf")
max_inputs = 0
nb_inputs = 0
for day in range(1, 26):
inputs = Counter()
for f in datadir.glob("*"):
# if not f.stem.isdigit():
# continue
if f.is_dir():
f = f / f"{year}" / f"{day}.in"
if f.is_file():
inputs.update([f.read_text().strip()])
v = list(inputs.values())
values.append((len(v), sum(v)))
if len(v) != 0:
min_inputs = min(min_inputs, len(v))
max_inputs = max(max_inputs, len(v))
nb_inputs = max(nb_inputs, sum(v))
row = [f"{year}"]
for a, b in values:
if a == min_inputs == max_inputs:
a = f"\033[34m{a}{RESET}"
elif a == min_inputs:
a = f"{GREEN}{a}{RESET}"
elif a == max_inputs:
a = f"{MAGENTA}{a}{RESET}"
b = f"{YELLOW}{b}{RESET}" if b == nb_inputs else f"{b}"
row.append(f"{a} / {b}")
row.append(f"{GREEN}{min_inputs:2}{RESET} → {MAGENTA}{max_inputs:2}{RESET}")
row.append(f"{YELLOW}{nb_inputs:2}{RESET}")
t.append(row)
# print(tabulate.tabulate(t, headers=["Year"] + [day for day in range(1, 26)], tablefmt="rounded_outline"))
t.insert(0, ["year"] + list(range(1, 26)) + [f"{GREEN}↓{MAGENTA}↑{RESET} ≠", f"{YELLOW}max{RESET}"])
t = transpose(t)
t.pop(0)
print(
tabulate.tabulate(
t,
headers=["Day"] + [year for year in range(2015, 2025)],
stralign="right",
tablefmt="rounded_outline",
)
)