-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel1.py
40 lines (26 loc) · 1.03 KB
/
level1.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
from collections import Counter
import os
from typing import List
def run_level(infile: str, input: List[str], outfile: str) -> str:
return '\n'.join(' '.join(str(i[b]) for b in 'WDSA') for i in (Counter(x) for x in input[1:]))
#####################################
def is_input_file(infile: str) -> bool:
return infile.endswith('.in')
def get_outfile(infile: str) -> str:
return infile.split('.in')[0] + '.out'
if __name__ == '__main__':
level = os.path.basename(__file__).split('.py')[0]
print(os.getcwd())
leveldir = os.path.join(os.path.dirname(__file__), '../levels/' + level + '/')
for file in os.listdir(leveldir):
infile = leveldir + file
if not is_input_file(infile):
continue
with open(infile) as f:
content = f.readlines()
outfile = get_outfile(infile)
result = run_level(infile, content, outfile)
if result and len(result) > 0:
with open(outfile, 'w') as f:
f.write(result)
f.write('\n')