generated from Gophing-Around/hashcode-golang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
algo2.go
48 lines (39 loc) · 1.02 KB
/
algo2.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
package main
func algorithm2(
config Config,
streets []*Street,
carsPaths []*CarsPaths,
streetsMap map[string]*Street,
intersectionMap map[int]*Intersection,
intersectionsList []*Intersection,
) []output {
out := make([]output, 0)
for tick := 0; tick < config.simuDuration; {
tick++
}
for _, intersection := range intersectionsList {
streetTimes := make([]StreetTime, 0)
totScore := 0
for _, street := range intersection.incomingStreets {
totScore += int(street.score)
// fmt.Printf("STREET %s - score: %d.\n", street.name, street.score)
}
if totScore == 0 {
continue
}
for _, street := range intersection.incomingStreets {
if street.score == 0 {
continue
}
streetTimes = append(streetTimes, StreetTime{
name: street.name,
greenLigthDuration: int(street.score) * config.simuDuration / totScore, // / len(intersection.incomingStreets),
})
}
out = append(out, output{
intersectionId: intersection.id,
streetsTime: streetTimes,
})
}
return out
}