diff --git a/day19/sol2.py b/day19/sol2.py index 738bcc9..da5bf69 100644 --- a/day19/sol2.py +++ b/day19/sol2.py @@ -12,6 +12,14 @@ def solve(file): n += 1 if len(x) > 1: for i in range(1,len(x)): + # note: i originally tried to compute this as + # n += ways(x[i:]) * ways(x[i:]) + # however that gives an overcount as, for example, + # rrr can be broken up as (r)[(r)(r)] or [(r)(r)](r) but + # for the purpose of the puzzle those are both equivalent - + # only the leaf nodes count (r r r), not the structure of the tree. + # the fix is to only recurse on one side of the cut (doesn't + # matter which one). if x[:i] in ds: n += ways(x[i:]) #print("ways(%s) = %s"%(x,n))