Structure
This commit is contained in:
31
day01/ex2/main.go
Normal file
31
day01/ex2/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"aoc2022/day01/common"
|
||||
)
|
||||
|
||||
func main() {
|
||||
inventories := common.Parse(*bufio.NewScanner(os.Stdin))
|
||||
|
||||
largestInventoriesTotal := []int{0, 0, 0}
|
||||
largestInventoriesIndex := []int{-1, -1, -1}
|
||||
for i := 0; i < 3; i++ {
|
||||
for index, inventory := range inventories {
|
||||
currentTotal := inventory.GetTotal()
|
||||
if currentTotal > largestInventoriesTotal[i] && index != largestInventoriesIndex[0] && index != largestInventoriesIndex[1] {
|
||||
largestInventoriesTotal[i] = currentTotal
|
||||
largestInventoriesIndex[i] = index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sum := 0
|
||||
for _, inventoryTotal := range largestInventoriesTotal {
|
||||
sum += inventoryTotal
|
||||
}
|
||||
|
||||
fmt.Println(sum)
|
||||
}
|
||||
Reference in New Issue
Block a user