46 lines
908 B
Go
46 lines
908 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"internal/day04"
|
|
"internal/util"
|
|
)
|
|
|
|
func main() {
|
|
data := util.ReadInput()
|
|
shifts := day04.ParseInput(data)
|
|
guards := day04.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]*day04.Guard) (*day04.Guard, int) {
|
|
var sleepiest *day04.Guard
|
|
for _, guard := range data {
|
|
if sleepiest == nil {
|
|
sleepiest = guard
|
|
continue
|
|
}
|
|
|
|
if guard.SleepTotal > sleepiest.SleepTotal {
|
|
sleepiest = guard
|
|
}
|
|
}
|
|
|
|
sleepiestMinute := -1
|
|
sleepiestCount := 0
|
|
for minute, sleepiness := range sleepiest.Sleep {
|
|
if sleepiness > sleepiestCount {
|
|
sleepiestCount = sleepiness
|
|
sleepiestMinute = minute
|
|
}
|
|
}
|
|
|
|
return sleepiest, sleepiestMinute
|
|
}
|