Skip to content

Instantly share code, notes, and snippets.

@micimize
Created April 2, 2020 20:30
Show Gist options
  • Save micimize/f8133f6cc34c8722f82d5a5086920f6a to your computer and use it in GitHub Desktop.
Save micimize/f8133f6cc34c8722f82d5a5086920f6a to your computer and use it in GitHub Desktop.
why did I bother
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