Fixed a bug in solve2

master
Andy Teijelo Pérez 2016-11-22 06:49:57 -05:00
parent 354e05db14
commit a2fa29ab4b
1 changed files with 4 additions and 2 deletions

View File

@ -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,)