day2, part2
This commit is contained in:
parent
0f9d7ccbe9
commit
afde84519f
|
@ -40,9 +40,7 @@ func Run() int {
|
|||
line := scanner.Text()
|
||||
game := ReadLine(line)
|
||||
log.Printf("reading %s got game %+v it is %t", line, game, game.isPossible(Restriction))
|
||||
if game.isPossible(Restriction) {
|
||||
result += game.Num
|
||||
}
|
||||
result += game.minKubesPower()
|
||||
}
|
||||
|
||||
return result
|
||||
|
@ -60,6 +58,30 @@ func (g Game)isPossible(restriction map[string]int) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (g Game)minKubesPower() int {
|
||||
runner := map[string]int{
|
||||
"red": 0,
|
||||
"blue": 0,
|
||||
"green": 0,
|
||||
}
|
||||
|
||||
for _, set := range g.Sets {
|
||||
for color, seenAmount := range set {
|
||||
if runner[color] < seenAmount {
|
||||
runner[color] = seenAmount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := 1
|
||||
for _, maxSeenAmount := range runner {
|
||||
result *= maxSeenAmount
|
||||
}
|
||||
|
||||
log.Printf(">>> for %+v min kubes are %+v and minPower is %n", g, runner, result)
|
||||
return result
|
||||
}
|
||||
|
||||
func ReadLine(line string) Game {
|
||||
result := Game{}
|
||||
result.Sets = make([]map[string]int, 0)
|
||||
|
@ -83,7 +105,7 @@ func ReadLine(line string) Game {
|
|||
// line like this
|
||||
// 8 green, 6 blue, 20 red
|
||||
func readSet(setLine string) map[string]int {
|
||||
log.Printf("> reading set: %s", setLine)
|
||||
// log.Printf("> reading set: %s", setLine)
|
||||
result := make(map[string]int)
|
||||
itemLines := strings.Split(setLine, ",")
|
||||
for _, line := range itemLines {
|
||||
|
|
Loading…
Reference in New Issue