diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02e925c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +*.sw* +.DS_Store + diff --git a/2018-08-06-earliest.py b/2018-08-06-earliest.py new file mode 100644 index 0000000..e8dafc7 --- /dev/null +++ b/2018-08-06-earliest.py @@ -0,0 +1,26 @@ + + +class Date: + + def __init__(self, date_string): + self.month, self.day, self.year = split_date_string(date_string) + + def __str__(self): + return f'{self.month:02}/{self.day:02}/{self.year}' + + def __lt__(self, other): + for attr in ['year', 'month', 'day']: + if getattr(self, attr) < getattr(other, attr): + return True + elif getattr(self, attr) > getattr(other, attr): + return False + + +def get_earliest(*date_strings): + dates = [Date(date_string) for date_string in date_strings] + return str(min(dates)) + + +def split_date_string(date_string): + month, day, year = date_string.split('/') + return int(month), int(day), int(year) diff --git a/__pycache__/earliest.cpython-36.pyc b/__pycache__/earliest.cpython-36.pyc new file mode 100644 index 0000000..4a49c6f Binary files /dev/null and b/__pycache__/earliest.cpython-36.pyc differ