About February 02, 2020 * This is a Python article.

Introduction

One day in 2019

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.

What is February 02, 2020?

"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].

Investigation

Constraint

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.

program

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))

result

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 conclusion

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

About February 02, 2020 * This is a Python article.
About Go error handling * This is a rough article.
Is this string a decimal?
Is this a system trade?
Python list is not a list
A memorandum about Python mock
This is a webiopi question
What is a python map?
A note about [python] __debug__
i! i! ← This is a mathematical formula
[Python] What is a zip function?
[Python] What is a with statement?
[Python] What is @? (About the decorator)
A note about mock (Python mock library)
A Java programmer studied Python. (About type)
Hash in Perl is a dictionary in Python
What is a dog? Python installation volume
[python] [meta] Is the type of python a type?
A story about Python pop and append
Why Python slicing is represented by a colon (:)
About python slices
About python comprehension
Python is easy
A Java programmer studied Python. (About functions (methods))
About Python tqdm.
Is sys.settrace, a python genius feature, another language?
A Java programmer studied Python. (About the decorator)
[Python] Qiita article information is pushed into mongoDB
About python, class
About the difference between "==" and "is" in python
A memo about writing merge sort in Python
About python inheritance
A note about the python version of python virtualenv
About python, range ()
This is the only basic review of Python ~ 1 ~
Data analysis in Python: A note about line_profiler
This is the only basic review of Python ~ 2 ~
A story about running Python on PHP on Heroku
Think about building a Python 3 environment in a Mac environment
What is python
A memorandum about the Python tesseract wrapper library
Launch a shell while a Python script is running
Python is instance
This is the only basic review of Python ~ 3 ~
About python reference
Judge whether it is a prime number [Python]
About Python decorators
A story about modifying Python and adding functions
[Python] About multi-process
Tell me what a conformal map is, Python!
What is Python
I thought about why Python self is necessary with the feeling of a Python interpreter
Check if the string is a number in python
This is a sample of function application in dataframe.
A story about making 3D space recognition with Python
Write about building a Python environment for writing Qiita Qiita
[Python] This is easy! Search for tweets on Twitter
Note that writing like this with ruby is writing like this with python
Python beginners talk about how to remember this much
A story about making Hanon-like sheet music with Python
A story about trying a (Golang +) Python monorepo with Bazel