Skip to content

Instantly share code, notes, and snippets.

@alcatrazEscapee
Created December 18, 2020 06:49
Show Gist options
  • Save alcatrazEscapee/4f60a6f4a407f3c670c1813885ab5ed8 to your computer and use it in GitHub Desktop.
Save alcatrazEscapee/4f60a6f4a407f3c670c1813885ab5ed8 to your computer and use it in GitHub Desktop.
The worst way to solve day 18
def main_badly(text: str):
lines = text.split('\n')
total = 0
class Int:
def __init__(self, i: int):
self.i = i
def __add__(self, other):
return Int(self.i * other.i)
def __mul__(self, other):
return Int(self.i + other.i)
for line in lines:
line = re.sub('([0-9])', r'Int(\1)', line).replace('*', '?').replace('+', '*').replace('?', '+')
total += eval(line).i
print('Part 2:', total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment