Day 4 solution, part 2.
This commit is contained in:
parent
b80c5a47bc
commit
1615406a28
37
2018/day04-2.go
Normal file
37
2018/day04-2.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"internal/guards"
|
||||
"internal/util"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := util.ReadInput()
|
||||
shifts := guards.ParseInput(data)
|
||||
guards := guards.BuildGuards(shifts)
|
||||
|
||||
sleepiest, sleepiestMinute := FindSleepiestData(guards)
|
||||
|
||||
fmt.Printf("Sleepiest Guard: %d\n", sleepiest.ID)
|
||||
fmt.Printf("Sleepiest Minute: %d\n", sleepiestMinute)
|
||||
fmt.Printf("Result: %d\n", sleepiest.ID*sleepiestMinute)
|
||||
}
|
||||
|
||||
func FindSleepiestData(data map[int]*guards.Guard) (*guards.Guard, int) {
|
||||
var sleepiest *guards.Guard
|
||||
var minute, value int
|
||||
|
||||
for _, guard := range data {
|
||||
for i := 0; i < 60; i++ {
|
||||
if guard.Sleep[i] > value {
|
||||
sleepiest = guard
|
||||
minute = i
|
||||
value = guard.Sleep[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sleepiest, minute
|
||||
}
|
Loading…
Reference in New Issue
Block a user