day 19 note
parent
d6b6bb979e
commit
074a6e3721
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue