You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
aoc2020/day07/lib.go

44 lines
697 B

package day07
func canHoldType(bagType string, canHold string) bool {
for _, bag := range rows {
if bag.Type == bagType {
if bag.Carries[canHold] > 0 {
return true
}
if len(bag.Carries) > 0 {
canCarry := false
for carry := range bag.Carries {
if canHoldType(carry, canHold) {
canCarry = true
}
}
return canCarry
}
}
}
return false
}
func getRecursiveContents(bagType string) int {
for _, bag := range rows {
if bag.Type == bagType {
if len(bag.Carries) == 0 {
return 0
}
sum := 0
for carry, amount := range bag.Carries {
sum += amount + amount*getRecursiveContents(carry)
}
return sum
}
}
return 0
}