DFS
2016-12-07 17:27:40 UTC
Get the min and max from a list of dates formatted like this:
10-Mar-1998
20-Aug-1997
06-Sep-2009
23-Jan-2010
05-Nov-2010
03-Sep-2009
07-Nov-2014
08-Mar-2013
My 5-line solution (python data structures only)
----------------------------------------------------------------
dt=['10-Mar-1998','20-Aug-1997','06-Sep-2009','23-Jan-2010','05-Nov-2010','03-Sep-2009','07-Nov-2014','08-Mar-2013']
m=[('Dec','12'),('Nov','11'),('Oct','10'),('Sep','09'),('Aug','08'),('Jul','07'),('Jun','06'),('May','05'),('Apr','04'),('Mar','03'),('Feb','02'),('Jan','01')]
dt2=[]
for d in dt:dt2.append((d[-4:]+dict(m)[d[3:6]]+d[:2],d))
print min(dt2)[1]+'\n'+max(dt2)[1]
----------------------------------------------------------------
$python getminmax.py
20-Aug-1997
07-Nov-2014
<quote>
My children, both were introduced to Linux when in grade 9-10.
By the time they left high school they were capable of installing and
configuring their own Linux systems. Now they are in university, one
is in 4th year doing mathematics concentrating on discrete
mathematics, hoping to do masters in AI. The other is in 3rd year CS.
They can both code circles around you.
</quote>
Bring those little idiots on! If they can code circles around me, they
can replicate that functionality in another language, in approx the same
# of lines, using only builtin data structures.
10-Mar-1998
20-Aug-1997
06-Sep-2009
23-Jan-2010
05-Nov-2010
03-Sep-2009
07-Nov-2014
08-Mar-2013
My 5-line solution (python data structures only)
----------------------------------------------------------------
dt=['10-Mar-1998','20-Aug-1997','06-Sep-2009','23-Jan-2010','05-Nov-2010','03-Sep-2009','07-Nov-2014','08-Mar-2013']
m=[('Dec','12'),('Nov','11'),('Oct','10'),('Sep','09'),('Aug','08'),('Jul','07'),('Jun','06'),('May','05'),('Apr','04'),('Mar','03'),('Feb','02'),('Jan','01')]
dt2=[]
for d in dt:dt2.append((d[-4:]+dict(m)[d[3:6]]+d[:2],d))
print min(dt2)[1]+'\n'+max(dt2)[1]
----------------------------------------------------------------
$python getminmax.py
20-Aug-1997
07-Nov-2014
<quote>
My children, both were introduced to Linux when in grade 9-10.
By the time they left high school they were capable of installing and
configuring their own Linux systems. Now they are in university, one
is in 4th year doing mathematics concentrating on discrete
mathematics, hoping to do masters in AI. The other is in 3rd year CS.
They can both code circles around you.
</quote>
Bring those little idiots on! If they can code circles around me, they
can replicate that functionality in another language, in approx the same
# of lines, using only builtin data structures.