solve part 2
This commit is contained in:
parent
192cf946b9
commit
5430cd0fed
15
day7/main.go
15
day7/main.go
|
@ -32,6 +32,20 @@ func HasShinyGold(bags Bags, b string, c []Bag) bool {
|
|||
return t
|
||||
}
|
||||
|
||||
func CountBags(bags Bags, bag Bag, mul int) int {
|
||||
fmt.Printf("#%v\t%d\n",bag, mul)
|
||||
c := bags[bag.Color]
|
||||
if len(c) == 0 { // dead end
|
||||
return 0
|
||||
}
|
||||
var s int
|
||||
for _, b := range c {
|
||||
s += b.Count*mul
|
||||
s += CountBags(bags, b, b.Count*mul)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func main() {
|
||||
// failed regex that might be worth revisiting:
|
||||
//linere, err := regexp.Compile(`(\w+ \w+) bags contain (?:\d+ (\w+ \w+) bags?, )*?\d+ (\w+ \w+) bags?\.`)
|
||||
|
@ -67,4 +81,5 @@ func main() {
|
|||
}
|
||||
}
|
||||
fmt.Println(total)
|
||||
fmt.Println(CountBags(bags, Bag{Color: "shiny gold"}, 1))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue