-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileReader.py
More file actions
63 lines (42 loc) · 1.45 KB
/
fileReader.py
File metadata and controls
63 lines (42 loc) · 1.45 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
import os
import glob
from inputDomain.CarPath import CarPath
from inputDomain.Street import Street
def loadInputFiles():
path = 'practiceHashcode2021/input_data/'
list_of_files = glob.glob(os.path.join(os.getcwd(), path + "*.txt"))
return sorted( list_of_files, key = lambda x: os.stat(os.path.join(path, x)).st_size)
def getLines(file):
with open(os.path.join(os.getcwd(), file), "r") as f:
content = f.read()
lines = content.split("\n")
return list(filter(None, lines))
def parseStreets(lines):
streetList = []
for index in range(len(lines)):
streetList.append(Street(lines[index].split(" ")))
return streetList
def parseCarPaths(lines):
carPaths = []
for index in range(len(lines)):
carPaths.append(CarPath(lines[index].split(" ")[1:]))
return carPaths
def parseInput(file):
lines = getLines(file)
duration, numIntersections, numStreets, numCars, points = lines[0].split(
" ")
streets = parseStreets(lines[1:int(numStreets)+1])
carPaths = parseCarPaths(lines[int(numStreets)+1:])
return duration, numIntersections, numStreets, numCars, points, streets, carPaths
"""
print('streets')
print(streets)
print('cars')
print(carPaths)
print ('duration: ' + duration
+ '\n numIntersections: ' + numIntersections
+ '\n numStreets: ' + numStreets
+ '\n numCars: ' + numCars
+ '\n points: ' + points )
"""
# paintMap(streets)