-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (36 loc) · 1.1 KB
/
main.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
from os import walk
import score
import solve
# Hardcoded output file names
output_files = [
'out/a_out',
'out/b_out',
'out/c_out',
'out/d_out',
'out/e_out',
'out/f_out',
]
def build_paths():
""" Reads files from './in' directory and maps to appropriate output
file name.
"""
_, _, input_files = next(walk('./in'))
_input_files = sorted(input_files)
input_files = ['in/' + input_file for input_file in _input_files]
return sorted(set(zip(input_files, output_files)), key=lambda t: t[1])
def main(file):
""" The file handler. Reads all input files and passes the string to
the solver. Write the solvers output string to the appropriate file.
"""
with open(file[0], 'r') as inp, open(file[1], 'w') as out:
# Call appropriate solver
out_str = solve.solve(inp)
# Copy string data to solver
data = inp.read()
# Create output file
out.write(out_str)
print(f'DONE: {file[0]}, SCORE: {score.score(data, out_str)}')
if __name__ == '__main__':
files = build_paths()
for file in files:
main(file)