Initial commit
This commit is contained in:
commit
97a4330bc0
110 changed files with 7006 additions and 0 deletions
34
2024/7/one.py
Normal file
34
2024/7/one.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
with open(input_file) as fd:
|
||||
lines = [line.rstrip() for line in fd.readlines()]
|
||||
|
||||
final = 0
|
||||
for line in lines:
|
||||
spli = line.split()
|
||||
res = int(spli[0][:-1])
|
||||
nums = [int(num) for num in spli[1:]]
|
||||
|
||||
def check(tot: int, nums: list[int]) -> bool:
|
||||
for op in (int.__add__, int.__mul__):
|
||||
ntot = op(tot, nums[0])
|
||||
if ntot > res:
|
||||
continue
|
||||
if len(nums) == 1:
|
||||
if ntot == res:
|
||||
return True
|
||||
else:
|
||||
if check(ntot, nums[1:]):
|
||||
return True
|
||||
return False
|
||||
|
||||
if check(nums[0], nums[1:]):
|
||||
final += res
|
||||
|
||||
print(final)
|
||||
|
||||
# 2664444091381: too low
|
37
2024/7/two.py
Normal file
37
2024/7/two.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
with open(input_file) as fd:
|
||||
lines = [line.rstrip() for line in fd.readlines()]
|
||||
|
||||
|
||||
def concat(a: int, b: int) -> int:
|
||||
return int(str(a) + str(b))
|
||||
|
||||
|
||||
final = 0
|
||||
for line in lines:
|
||||
spli = line.split()
|
||||
res = int(spli[0][:-1])
|
||||
nums = [int(num) for num in spli[1:]]
|
||||
|
||||
def check(tot: int, nums: list[int]) -> bool:
|
||||
for op in (int.__add__, int.__mul__, concat):
|
||||
ntot = op(tot, nums[0])
|
||||
if ntot > res:
|
||||
continue
|
||||
if len(nums) == 1:
|
||||
if ntot == res:
|
||||
return True
|
||||
else:
|
||||
if check(ntot, nums[1:]):
|
||||
return True
|
||||
return False
|
||||
|
||||
if check(nums[0], nums[1:]):
|
||||
final += res
|
||||
|
||||
print(final)
|
Loading…
Add table
Add a link
Reference in a new issue