Rename 2024 scripts for nicer ordering
This commit is contained in:
30
2024/d07.py
Normal file
30
2024/d07.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from lib import get_data
|
||||
from lib import ints
|
||||
|
||||
data = get_data(__file__)
|
||||
|
||||
|
||||
def combs(acc, rest, part_2=False):
|
||||
if rest == []:
|
||||
return acc
|
||||
|
||||
nacc = []
|
||||
for a in acc:
|
||||
nacc.append(a + rest[0])
|
||||
nacc.append(a * rest[0])
|
||||
if part_2:
|
||||
nacc.append(int(str(a) + str(rest[0])))
|
||||
return combs(nacc, rest[1:], part_2)
|
||||
|
||||
|
||||
t1, t2 = 0, 0
|
||||
for line in data.splitlines():
|
||||
xs = ints(line)
|
||||
expected = xs[0]
|
||||
if xs[0] in combs([xs[1]], xs[2:]):
|
||||
t1 += xs[0]
|
||||
if xs[0] in combs([xs[1]], xs[2:], True):
|
||||
t2 += xs[0]
|
||||
|
||||
print(t1)
|
||||
print(t2)
|
||||
Reference in New Issue
Block a user