2024(6): get rekt
This commit is contained in:
37
2024/07/part1.py
Normal file
37
2024/07/part1.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
def load_data(filename="input"):
|
||||||
|
with open(filename, "r") as fp:
|
||||||
|
lines = fp.read().splitlines()
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
splits = line.split(": ")
|
||||||
|
test_value = int(splits[0])
|
||||||
|
nums = list(map(int, splits[1].split(" ")))
|
||||||
|
|
||||||
|
#print(test_value)
|
||||||
|
#print(nums)
|
||||||
|
#print()
|
||||||
|
|
||||||
|
ret.append((test_value, nums))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def recurse_it_all(nums):
|
||||||
|
def s(start, nums):
|
||||||
|
if len(nums) == 1:
|
||||||
|
return [start + nums[0], start * nums[0]]
|
||||||
|
return s(start + nums[0], nums[1:]) + s(start * nums[0], nums[1:])
|
||||||
|
|
||||||
|
return s(nums[0], nums[1:])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
data = load_data()
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
for test_value, nums in data:
|
||||||
|
if test_value in recurse_it_all(nums):
|
||||||
|
total += test_value
|
||||||
|
|
||||||
|
print(total)
|
||||||
Reference in New Issue
Block a user