# Next date in the future that satisfies the following conditions

When is the next time that a date will satisfy the following conditions:

• YYYY days from MM/DD/YYYY is also the (DD)th day of a month. Note that YYYY stands for the year.

• All eight digits of MM/DD/YYYY is all distinct.

• All eight digits of YYYY days from MM/DD/YYYY are also all distinct.

Bonus question:

When is the next time that a date will not only satisfy the above conditions, but also with MM/DD/YYYY and YYYY days from MM/DD/YYYY falling on the same day of the week?

This unpolished script:

from datetime import date, timedelta

y = date.today().year
for year in range(y,9877):
yhits = set(str(year))
if len(yhits) < 4: continue
for month in ('01','02','03','04','05','06','07','08','09','10','12'):
mhits = yhits | set(month)
if len(mhits) < 6: continue
for day in range(1,1+[31,28+(year%400 > 0 and year%4 == 0),31,30,31,30,31,31,30,31,30,31][int(month)-1]):
DD = '0'*(day < 10) + str(day)
dhits = mhits | set(DD)
if len(dhits) < 8: continue
curr = date(year,int(month),day)
nex = curr + timedelta(days=year)
if len(set(str(nex))) == 9 and nex.day == curr.day: print(str(curr),str(nex))

yields all the upcoming dates satisfying the three conditions. The first of these is

June 13th, 2587 which is 2587 days before July 13th, 2594.

The first that also satisfies the bonus criterion (equivalent to being in a year divisible by 7) is

Monday, September 12th, 3864, which is 3864 days before Monday, April 12th, 3875.