From a2fa29ab4b9e9c6ef95d2fbc7a2c8a9ec87d6808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andy=20Teijelo=20P=C3=A9rez?= Date: Tue, 22 Nov 2016 06:49:57 -0500 Subject: [PATCH] Fixed a bug in solve2 --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 0986840..514041a 100755 --- a/main.py +++ b/main.py @@ -70,8 +70,10 @@ def solve2(width, pattern, constraints=None): maxgap = width - sum(pattern[1:]) - (len(pattern) - 1) - p for gap in range(maxgap + 1): - e = expand_solution((gap,), gap + p + 1, (p,)) - if not matches(e, constraints[:gap + p + 1]): + # constraint width + cw = (gap + p + 1) if len(pattern) > 1 else width + e = expand_solution((gap,), cw, (p,)) + if not matches(e, constraints[:cw]): continue if len(pattern) == 1: yield (gap,)