Add code for 2015 advent that I did historically.
This commit is contained in:
parent
13968ed94e
commit
9e9e556c73
25 changed files with 598 additions and 0 deletions
25
day_8/solution.py
Normal file
25
day_8/solution.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import re
|
||||
|
||||
|
||||
def get_code_chars(string):
|
||||
return len(string)
|
||||
|
||||
def get_mem_chars(string):
|
||||
return len(eval(f'"{string[1:-1]}"'))
|
||||
|
||||
def get_encoded_size(string):
|
||||
return len(f'{re.escape(string)}') + 2
|
||||
|
||||
|
||||
with open("input", "r") as data:
|
||||
encoded_code_sum = 0
|
||||
code_char_sum = 0
|
||||
mem_char_sum = 0
|
||||
for line in data:
|
||||
line = line.strip()
|
||||
encoded_code_sum += get_encoded_size(line)
|
||||
code_char_sum += get_code_chars(line)
|
||||
mem_char_sum += get_mem_chars(line)
|
||||
|
||||
print(f"Part 1 Solution: {code_char_sum - mem_char_sum}")
|
||||
print(f"Part 2 Solution: {encoded_code_sum - code_char_sum}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue