Fixed a bug in solve2

This commit is contained in:
Andy Teijelo Pérez 2016-11-22 06:49:57 -05:00
parent 354e05db14
commit a2fa29ab4b

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