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