Skip to content

Instantly share code, notes, and snippets.

@EugeneFeshchenko
Created November 27, 2015 11:42
Show Gist options
  • Save EugeneFeshchenko/70e4c5e8e2ed10a8d2fb to your computer and use it in GitHub Desktop.
Save EugeneFeshchenko/70e4c5e8e2ed10a8d2fb to your computer and use it in GitHub Desktop.
import datetime
import itertools
with open('file.txt', 'r') as f:
read_data = f.read()
print 'Input {0}'.format(read_data)
a = []
a = read_data.split('/')
a = [int(x) for x in a]
days = []
months = []
years = []
comb=[]
comb = list(itertools.permutations(a, 3))
dates = []
for i in comb:
four_digits = 0
if len(str(i[2])) == 1 or len(str(i[2])) == 2:
four_digits += i[2] + 2000
try:
date = datetime.date(day = i[0], month = i[1], year = four_digits)
except:
pass
else:
dates.append(date)
for b in dates:
print b.strftime('%Y-%m-%d')
if dates:
print 'Earliest date is', min(dates)
else:
print 'Is illegal'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment