From f287551e1cf9abea84dde97f5ceb0b9c4420acb0 Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Mon, 9 May 2022 08:26:40 +0900 Subject: [PATCH] exclude if gear size is less than 1 --- extra/gearing-up-for-destruction/solution.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extra/gearing-up-for-destruction/solution.py b/extra/gearing-up-for-destruction/solution.py index 65e0dd3..dfd9359 100644 --- a/extra/gearing-up-for-destruction/solution.py +++ b/extra/gearing-up-for-destruction/solution.py @@ -3,7 +3,7 @@ def solution(pegs): if len(pegs) % 2 == 0: s = 2 * odd - 2 * even - pegs[-1] + pegs[0] - if s <= 0: + if 2*s < 3: return [-1, -1] if s % 3 == 0: return [2*s/3, 1] @@ -11,7 +11,7 @@ def solution(pegs): return [2*s, 3] else: s = 2 * odd - 2 * even + pegs[-1] + pegs[0] - if s <= 0: + if 2*s < 1: return [-1, -1] return [2*s, 1] @@ -28,6 +28,8 @@ def sum_odd_even(pegs): tests = [ ([4, 30, 50], [12, 1]), ([4, 17, 50], [-1, -1]), + ([1, 2], [-1, -1]), + ([1, 2, 3], [-1, -1]), ] for i, o in tests: