Structure

This commit is contained in:
2022-12-01 07:50:35 +01:00
parent d4eb4a757c
commit 9fe1abe08c
5 changed files with 15 additions and 10 deletions

31
day01/ex2/main.go Normal file
View 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)
}