2024(3): Solved seconf puzzle
Renamed file for first puzzle to be able to import the process_line function properly. Co-authored-by: Marit Nuijten <marit.nuijten@gmail.com>
This commit is contained in:
24
2024/3/2.py
Normal file
24
2024/3/2.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from puzzle1 import process_line as process_line_dumb
|
||||||
|
|
||||||
|
|
||||||
|
def has_do_or_dont(line):
|
||||||
|
return "do()" in line or "don't()" in line
|
||||||
|
|
||||||
|
def process_string(string):#, enabled: bool):
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
do_lines = string.split("do()")
|
||||||
|
for do_line in do_lines:
|
||||||
|
good_line = do_line.split("don't()")[0]
|
||||||
|
result += process_line_dumb(good_line)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#result = 0
|
||||||
|
with open("input", "r") as fp:
|
||||||
|
full_string = fp.read()
|
||||||
|
# while (line := fp.readline()):
|
||||||
|
result = process_string(full_string)
|
||||||
|
|
||||||
|
print(f"The sum of all multiplications equals {result}.")
|
||||||
BIN
2024/3/__pycache__/puzzle1.cpython-312.pyc
Normal file
BIN
2024/3/__pycache__/puzzle1.cpython-312.pyc
Normal file
Binary file not shown.
@ -9,9 +9,10 @@ def process_line(line):
|
|||||||
|
|
||||||
#test = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
|
#test = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
|
||||||
|
|
||||||
result = 0
|
if __name__ == "__main__":
|
||||||
with open("input", "r") as fp:
|
result = 0
|
||||||
while (line := fp.readline()):
|
with open("input", "r") as fp:
|
||||||
result += process_line(line)
|
while (line := fp.readline()):
|
||||||
|
result += process_line(line)
|
||||||
|
|
||||||
print(f"The sum of all multiplications equals {result}.")
|
print(f"The sum of all multiplications equals {result}.")
|
||||||
Reference in New Issue
Block a user