package day_11 import ( "fmt" "strings" "rpjosh.de/adventOfCode/pkg/utils" ) type Day struct{} type MonkeyData struct { operation MonkeyOperation test MonkeyTest items []int inspectedItems int } type MonkeyOperation struct { multiply bool sameValue bool value int } type MonkeyTest struct { divValue int trueThrowTo int falseThrowTo int } func (d *Day) Part1(in string) string { return d.Perform(in, false, 20) } func (d *Day) Part2(in string) string { return d.Perform(in, true, 10000) } func (d *Day) Perform(in string, part2 bool, iterations int) string { var monkeys []MonkeyData part2DivValues := 1 for i, val := range strings.Split(in, "\n") { mongo := i / 7 // Parse monkey data switch i % 7 { case 0: { monkeys = append(monkeys, MonkeyData{}) } case 1: { // Starting items items := strings.Split(val[18:], ", ") //monkeys[mongo].items = make([]int, 10) for _, item := range items { monkeys[mongo].items = append(monkeys[mongo].items, utils.ToInt(item)) } } case 2: { // Operation >19 maxOne { maxTwo = maxOne maxOne = monkey.inspectedItems } else if monkey.inspectedItems > maxTwo { maxTwo = monkey.inspectedItems } } return fmt.Sprintf("%d", maxOne*maxTwo) }