From 074a6e3721df3a50da470d8b6dba8a859e601d28 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Thu, 19 Dec 2024 08:10:58 +0000 Subject: [PATCH] day 19 note --- day19/sol2.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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))