Piotr Czajkowski 1 tuần trước cách đây
mục cha
commit
39a59262e3
1 tập tin đã thay đổi với 10 bổ sung3 xóa
  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--