From 952b3c123e7419ca7b22024012b84de3b21e2ef8 Mon Sep 17 00:00:00 2001 From: zevav Date: Mon, 13 Aug 2018 23:41:45 -0400 Subject: [PATCH] added earliest.py --- .gitignore | 4 ++++ 2018-08-06-earliest.py | 26 ++++++++++++++++++++++++++ __pycache__/earliest.cpython-36.pyc | Bin 0 -> 1321 bytes 3 files changed, 30 insertions(+) create mode 100644 .gitignore create mode 100644 2018-08-06-earliest.py create mode 100644 __pycache__/earliest.cpython-36.pyc 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 0000000000000000000000000000000000000000..4a49c6f434780dd55c0e7b98ef9a175b591ce27b GIT binary patch literal 1321 zcmZ8g&2G~`5Z)i#F=>iQRS@EUstO_bl2pJkRES2DQ!WJ|1*(&?IK)#pEqkl$owa9FOa&A&DA8u&W0|tGu7VB0*cUqmqF=mt1-VZtx7P;bm zKMJroc|1yluuTDVlouJUTSA;)#94KtFobHM+Ca5r)UA+Kg>^&1G-3;B$V2YVhOl)5 z%Z>&IAo>ZYs^e#*M@l-Uh8T)HTvAumx*u*^{Se)@K%D@^M=f+f^B?RSXm^O9-UtF3 znYDKnmUjgxV!UZ~vs9a5F&ghZg1xJLK&IP3tf>37n-#-2(|hfuF@)sM8kUdJJYs{E zTz(`CKNNQQ&QrFv8uKAOhJ8useX8)k*6HCX%07sG4ytN*{L6DXXLDY$0-BW+G%x8f z2ZmT*t${Tl^WEpRJk3qyRcRy5%YSeOnnFgA{{^BA>Q1obkUj^`ovirPWwv3rYLPvB L!$r8i8T$VK9(4$! literal 0 HcmV?d00001