-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
35 lines (29 loc) · 1.1 KB
/
util.py
File metadata and controls
35 lines (29 loc) · 1.1 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
from typing import List
from models.photo import Photo
from models.individual import Individual
def read_input(file_name: str) -> List[Photo]:
"""Read problem input from textfile and return Photo objects."""
with open(file_name, 'r') as f:
lines = [l.strip() for l in f.readlines()]
n = int(lines[0])
lines.pop(0)
photos = []
idx = 0
for line in lines:
elements = line.split(" ")
orientation = elements[0]
how_many_tags = int(elements[1])
if how_many_tags > 0:
tags = elements[2:]
photos.append(Photo(id=idx, orientation=orientation, tags=tags))
idx += 1
return photos
def write_output(i: Individual, file_name: str):
"""Write the solution in output file."""
with open(file_name, 'w') as f:
f.write(f'{len(i.slides)}\n')
for slide in i.slides:
if slide.photo2 is None:
f.write(f'{slide.photo1.id}\n')
else:
f.write(f'{slide.photo1.id} {slide.photo2.id}\n')