Last active
August 8, 2019 11:39
-
-
Save kaisugi/7224a4c5d70057125340ee4a1f84df9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Set | |
def incrementDate(date: Dict[str, int]) -> None: | |
if date["month"] == 12 and date["day"] == 31: | |
date["year"] += 1 | |
date["month"] = 1 | |
date["day"] = 1 | |
elif date["day"] == 31: | |
date["month"] += 1 | |
date["day"] = 1 | |
else: | |
date["day"] += 1 | |
def isValidFormatDate(date: Dict[str, int]) -> bool: | |
if date["day"] == 31: | |
if date["month"] in [2, 4, 6, 9, 11]: | |
return False | |
else: | |
return True | |
elif date["month"] == 2 and date["day"] == 30: | |
return False | |
elif date["month"] == 2 and date["day"] == 29: | |
if date["year"] % 400 == 0: | |
return True | |
elif date["year"] % 100 == 0: | |
return False | |
elif date["year"] % 4 == 0: | |
return True | |
else: | |
return False | |
else: | |
return True | |
tmpDate: Dict[str, int] = dict() | |
tmpDate["year"] = 2019 | |
tmpDate["month"] = 8 | |
tmpDate["day"] = 7 | |
incrementDate(tmpDate) | |
# test | |
# print(isValidFormatDate({"year": 2019, "month": 8, "day": 31})) | |
# print(not isValidFormatDate({"year": 2019, "month": 4, "day": 31})) | |
# print(not isValidFormatDate({"year": 2019, "month": 2, "day": 31})) | |
# print(not isValidFormatDate({"year": 2019, "month": 2, "day": 30})) | |
# print(not isValidFormatDate({"year": 2019, "month": 2, "day": 29})) | |
# print(isValidFormatDate({"year": 2019, "month": 2, "day": 28})) | |
# print(isValidFormatDate({"year": 2020, "month": 2, "day": 29})) | |
# print(not isValidFormatDate({"year": 2100, "month": 2, "day": 29})) | |
# print(isValidFormatDate({"year": 2400, "month": 2, "day": 29})) | |
while True: | |
if isValidFormatDate(tmpDate): | |
testStr = "{}{}{}".format(tmpDate["year"], tmpDate["month"], tmpDate["day"]) | |
n = len(testStr) | |
flg = True | |
tmpSet: Set[str] = set() | |
for i in range(n): | |
if testStr[i] in tmpSet: | |
flg = False | |
break | |
tmpSet.add(testStr[i]) | |
if flg: | |
print("{}/{}/{}".format(tmpDate["year"], tmpDate["month"], tmpDate["day"])) | |
break | |
incrementDate(tmpDate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment