Piotr Czajkowski 1 week ago
parent
commit
39a59262e3
1 changed files with 10 additions and 3 deletions
  1. 10 3
      13/code.go

+ 10 - 3
13/code.go

@@ -72,11 +72,18 @@ func calculate(machine Machine, button int) [2]int {
 	}
 
 	start := min(machine.x/machine.buttons[button].x, machine.y/machine.buttons[button].y)
+	if start > 100 {
+		start = 100
+	}
+
 	for start > 0 {
 		if (machine.x-start*machine.buttons[button].x)%machine.buttons[otherButton].x == 0 && (machine.y-start*machine.buttons[button].y)%machine.buttons[otherButton].y == 0 {
-			results[button] = start
-			results[otherButton] = (machine.x - start*machine.buttons[button].x) / machine.buttons[otherButton].x
-			return results
+			otherPushes := (machine.x - start*machine.buttons[button].x) / machine.buttons[otherButton].x
+			if otherPushes <= 100 {
+				results[button] = start
+				results[otherButton] = otherPushes
+				return results
+			}
 		}
 
 		start--