generated from Gophing-Around/hashcode-golang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 1.21 KB
/
main.go
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
package main
import (
"fmt"
"io/ioutil"
"sort"
"github.com/fredmaggiowski/gowq"
)
func main() {
files := []string{
// Uncomment the line with the desired files (add other lines if needed)
"a",
"b",
"c",
"d",
"e",
"f",
}
gowq.NewWQ(10)
for _, fileName := range files {
fmt.Printf("****************** INPUT: %s\n", fileName)
inputSet := readFile(fmt.Sprintf("./inputFiles/%s.txt", fileName))
fileLines := splitNewLines(inputSet)
config := buildConfig(fileLines[0])
// fmt.Printf("%+v\n", config)
streets, streetsMap, intersectionMap, intersectionsList := buildStreets(config, fileLines[1:])
carsPaths := buildCarsPaths(config, fileLines[1+config.nStreets:])
intersectionsList = sortIntersections(intersectionsList)
// printInputMetrics(input)
outputs := algorithm(config, streets, carsPaths, streetsMap, intersectionMap, intersectionsList)
result := buildOutput(outputs)
// printResultMetrics(result)
ioutil.WriteFile(fmt.Sprintf("./result/%s.txt", fileName), []byte(result), 0644)
}
}
func sortIntersections(list []*Intersection) []*Intersection {
sort.Slice(list, func(i, j int) bool {
return len(list[i].outcomingStreets) > len(list[j].outcomingStreets)
})
return list
}