From 232ead59864ddd5a4620a842763beaaa25d9e6ff Mon Sep 17 00:00:00 2001 From: Fedor Lyanguzov Date: Sat, 7 Dec 2024 08:54:58 +0300 Subject: [PATCH] 07.1, 07.2 python --- 07/07.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 07/07.py diff --git a/07/07.py b/07/07.py new file mode 100644 index 0000000..68669b2 --- /dev/null +++ b/07/07.py @@ -0,0 +1,30 @@ + + + + +data = open("input.txt").read().strip().split("\n") + +def f(t, l, x=0, i=0): + if i==len(l): + return t==x + return f(t, l, x+l[i], i+1) or \ + f(t, l, x*l[i], i+1) + +def f2(t, l, x=0, i=0): + if i==len(l): + return t==x + return f2(t, l, x+l[i], i+1) or \ + f2(t, l, x*l[i], i+1) or \ + f2(t, l, int(str(x)+str(l[i])), i+1) +s = 0 +s2 = 0 +for x in data: + t, l = x.split(': ') + t = int(t) + l = [int(y) for y in l.split()] + if f(t, l): + s += t + if f2(t, l): + s2 += t +print(s) +print(s2)