cut loop short if any value exceeds its limit

This commit is contained in:
onyx-and-iris 2023-12-02 22:40:24 +00:00
parent bf97f15d04
commit 5b1ca25d3f

View File

@ -21,7 +21,6 @@ var limits = map[string]int{
// isValidGame calculates if a game was possible based on the limits of each cube colour
func isValidGame(data string) (bool, error) {
valid := true
for _, colour := range []string{"red", "green", "blue"} {
m := regex[colour].FindAllStringSubmatch(data, -1)
for _, s := range m {
@ -30,12 +29,12 @@ func isValidGame(data string) (bool, error) {
return false, err
}
if n > limits[colour] {
valid = false
return false, nil
}
}
}
return valid, nil
return true, nil
}
// one returns the sum of ids for all games that were possible