From 47b85b052b5438f0e47b07d6c6bb901fcffe5441 Mon Sep 17 00:00:00 2001 From: npc-strider Date: Mon, 7 Dec 2020 18:37:16 +0800 Subject: [PATCH] update day 7 with recursive soln for part a --- 7/b.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/7/b.py b/7/b.py index 07a0a3f..87424be 100644 --- a/7/b.py +++ b/7/b.py @@ -21,4 +21,15 @@ def f(li,count): count += k return count -print( f(dictionary['shiny gold'],0) ) +print( f(dictionary['shiny gold'],0) ) #Part B + +def g(li): + for u in li: + if u == 'shiny gold': + return True + else: + if g(dictionary[u]) == True: + return True + +d = {x:g(dictionary[x]) for x in dictionary} +print(len({x for x in d if (d[x] == True)})) #Part A