feat: 2023/Day2/2

This commit is contained in:
s-prechtl 2023-12-10 06:57:30 +01:00
parent c00b7912e2
commit 4ee4d03c1f

View file

@ -20,12 +20,18 @@ func main() {
} }
games := strings.Split(string(content), "\n") games := strings.Split(string(content), "\n")
sum_of_possibles := 0 sum_of_powers := 0
for _, game := range games { for _, game := range games {
possible := true if game == "" {
continue
}
// possible := true
min_red := 0
min_blue := 0
min_green := 0
game_info := strings.Split(strings.Replace(game, "Game ", "", 1), ":") game_info := strings.Split(strings.Replace(game, "Game ", "", 1), ":")
gameId, err := strconv.Atoi(game_info[0]) game_id, err := strconv.Atoi(game_info[0])
if err != nil { if err != nil {
continue continue
} }
@ -37,7 +43,8 @@ func main() {
for _, cube := range cubes { for _, cube := range cubes {
amount, err := strconv.Atoi(strings.Split(strings.TrimSpace(cube), " ")[0]) cube = strings.TrimSpace(cube)
amount, err := strconv.Atoi(strings.Split(cube, " ")[0])
if err != nil { if err != nil {
fmt.Println(cube, "heast") fmt.Println(cube, "heast")
continue continue
@ -45,20 +52,23 @@ func main() {
color := strings.Split(cube, " ")[1] color := strings.Split(cube, " ")[1]
if color == "green" && amount > MAX_GREEN { if game_id == 3 {
possible = false fmt.Println(cube, amount, color)
} else if color == "red" && amount > MAX_RED {
possible = false
} else if amount > MAX_BLUE {
possible = false
}
} }
if possible == true { if color == "green" {
sum_of_possibles += gameId min_green = max(amount, min_green)
} else if color == "red" {
min_red = max(amount, min_red)
} else {
min_blue = max(amount, min_blue)
} }
} }
fmt.Println(min_red, min_green, min_blue)
sum_of_powers += min_green * min_red * min_blue
}
fmt.Println(sum_of_possibles) fmt.Println(sum_of_powers)
} }