Created
April 2, 2020 20:30
-
-
Save micimize/f8133f6cc34c8722f82d5a5086920f6a to your computer and use it in GitHub Desktop.
why did I bother
This file contains 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
class StupidNumber: | |
"""A stupid viral facebook arithmetic puzzle with overridden operators | |
""" | |
_number: int | |
def __init__(self, number: int): | |
self._number = number | |
def __add__(self, other): | |
return StupidNumber(self._number * (other._number + 1)) | |
def __repr__(self): | |
return f'StupidNumber({self._number})' | |
@classmethod | |
def parse(cls, expression: str): | |
a, b = expression.split('+') | |
return StupidNumber(int(a.strip())) + StupidNumber(int(b.strip())) | |
StupidNumber.parse('5 + 8') | |
#> StupidNumber(45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment