I came across a wonderful article.
[About April 5, 2013 * This is a Ruby article. | TECHSCORE BLOG](https://www.techscore.com/blog/2013/01/04/2013%E5%B9%B44%E6%9C%885%E6%97%A5%E3%81%AB%E3 % 81% A4% E3% 81% 84% E3% 81% A6-% E2% 80% BBruby% E3% 81% AE% E8% A8% 98% E4% BA% 8B% E3% 81% A7% E3% 81% 99% E3% 80% 82 /)
The following is a summary of the content.
--There is no duplication in the numbers that make up April 5, 2013. Wow! ――When was the last time? When is next time? Investigate by Ruby program! ――The last time was "○○○○ year ○○ month ○○ day" and the next time was "XXX month XX day"!
I personally read it with great interest and enjoyed it. (Please take a look!) It's good to be able to quickly investigate various things by using programming. I thought, "It's a great cut-next year (2020), 2 and 0 will already be used twice each year alone." At that time, I noticed something.
"Are ... February 02, 2020 uses only two numbers, 0 and 2 ...?"
This day is ... what ... it consists of only "0" and "2"! !!
From a different point of view than April 5, 2013, this day is also a rare day ...? I thought. So, let's examine the date that consists of two or less numbers like this. In the original story article, I used Ruby, but this time I will use Python. The execution environment is Google Colaboratory [^ Google Colaboratory].
This time, the year is 4 digits and the month and day are 2 digits. Therefore, the missing digits are filled with zeros (0). (Example: "1 year"-> "0001", "January"-> "January") Also, the target date is from January 01, 0001 to December 31, 9999.
Survey of applicable date
import datetime
from collections import Counter
#constant
START_DAY = datetime.datetime(1, 1, 1)
END_DAY = datetime.datetime(9999, 12, 31)
BORDER = 2
#Store the target date in the dictionary (January 01, 0001-December 31, 9999)
target_days = {}
today = START_DAY
while True:
target_days[today] = today
if (today == END_DAY):
break;
today = today + datetime.timedelta(days=1)
#Target days
print(len(days))
#Store the date corresponding to the condition that it is composed of two or less numbers in the dictionary ans
ans_days = {}
for today in target_days:
if (len(Counter(today.strftime("%Y%m%d"))) <= BORDER):
ans_days[today] = today
#Applicable days
print (len(ans_days))
#Applicability rate
print (len(ans_days)/len(target_days))
The target number of days this time was 3652059
days from January 01, 0001 to December 31, 9999. Among them, the date composed of two or less numbers such as February 02, 2020
was 928
day. Its probability for the whole was 0.0002541032332719707
, or once every 3935 days. Isn't it quite rare? (Although there is considerable unevenness, the pace is once every 10 years.) By the way, the following dates were applicable. (Omitted, excerpted.)
Calculation of applicable date
for today in ans_days:
print(ans_days[today].strftime("%Y/%m/%d"))
Execution result
January 01, 0001
January 10, 0001
January 11, 0001
(Omitted)
February 02, 2002
February 20, 2002
February 22, 2002
February 02, 2020
February 20, 2020
February 22, 2020
February 02, 2022
February 20, 2022
February 22, 2022
November 11, 2111
November 12, 2111
November 21, 2111
(Omitted)
September 09, 9999
November 11, 9999
November 19, 9999
The last time was February 22, 2002
, 18 years ago. It seems that there will be three times in 2020, including February 02, 2020
, and it seems that there will be three times in 2022. Next is 2111 ... it's a long way off ...
In this article, we investigated a date that consists of only two numbers, such as February 02, 2020. There were days close to February 20, 2020 and February 22, 2020, but in terms of probability, it was rare, about once every 10 years.
So (?), Thank you for 2019. : bow: I look forward to working with you in 2020. : bow:
(Added on January 2, 2019) It was published in the following article! Thank you!
-[Python] Qiita Weekly Stock Number Ranking [Automatic Update](Updated at 13:00 on January 1, 2020)
Recommended Posts