Created
December 18, 2020 06:49
-
-
Save alcatrazEscapee/4f60a6f4a407f3c670c1813885ab5ed8 to your computer and use it in GitHub Desktop.
The worst way to solve day 18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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