mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-25 03:40:49 +00:00
cut loop short if any value exceeds its limit
This commit is contained in:
parent
bf97f15d04
commit
5b1ca25d3f
@ -21,7 +21,6 @@ var limits = map[string]int{
|
|||||||
|
|
||||||
// isValidGame calculates if a game was possible based on the limits of each cube colour
|
// isValidGame calculates if a game was possible based on the limits of each cube colour
|
||||||
func isValidGame(data string) (bool, error) {
|
func isValidGame(data string) (bool, error) {
|
||||||
valid := true
|
|
||||||
for _, colour := range []string{"red", "green", "blue"} {
|
for _, colour := range []string{"red", "green", "blue"} {
|
||||||
m := regex[colour].FindAllStringSubmatch(data, -1)
|
m := regex[colour].FindAllStringSubmatch(data, -1)
|
||||||
for _, s := range m {
|
for _, s := range m {
|
||||||
@ -30,12 +29,12 @@ func isValidGame(data string) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if n > limits[colour] {
|
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
|
// one returns the sum of ids for all games that were possible
|
||||||
|
Loading…
Reference in New Issue
Block a user