3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2020年02月02日について ※Pythonの記事です。

Last updated at Posted at 2019-12-29

はじめに

2019年某日

ある素晴らしい記事に出会いました。

2013年4月5日について ※Rubyの記事です。 | TECHSCORE BLOG

以下は内容を要約したものです。

  • 2013年4月5日を構成する数字に重複がない。すごい!
  • 前回はいつ?次回はいつ?Rubyのプログラムによって調査!
  • 前回は「○○○○年○○月○○日」で次回は「××××年××月××日」でした!

個人的に興味深く読ませていただき、楽しませていただきました。(ぜひ、みなさまもご覧ください!)プログラミングを使うことでサクッと色々なことが調べられるのは良いですねー。「すごい切り口だな~来年(2020年)は年だけでもすでに2も0も2回ずつ使われているな~」と思っていました。そんなとき、あることに気が付きました。

2020年02月02日とは

「アレ……2020年02月02日は0と2の2つの数字しか使われていない……?」

この日は……なんと……“0”と“2”のみで構成されています!!

2013年4月5日とは異なる観点で、この日もレアな日なのでは……?と思いました。というわけで、このような2つ以下の数字で構成されている年月日を調べてみます。元ネタの記事ではRubyを使っていますが、今回はPythonを使います。実行環境はGoogle Colaboratory^Google Colaboratoryです。

調査

制約

今回、年を4桁、月と日を2桁とします。それゆえ、桁が足りない年月日はゼロ(0)によって埋めます。(例:「1年」→「0001年」、「1月」→「01月」)また、対象とする年月日を0001年01月01日~9999年12月31日とします。

プログラム

該当年月日の調査
import datetime
from collections import Counter

# 定数
START_DAY = datetime.datetime(1, 1, 1)
END_DAY = datetime.datetime(9999, 12, 31)
BORDER = 2

# 対象年月日を辞書に格納(0001年01月01日~9999年12月31日)
target_days = {}
today = START_DAY
while True:
    target_days[today] = today
    if (today == END_DAY):
        break;
    today = today + datetime.timedelta(days=1)

# 対象日数
print(len(days))

# 2つ以下の数字によって構成されるという条件に該当する年月日を辞書ansに格納
ans_days = {}
for today in target_days:
    if (len(Counter(today.strftime("%Y%m%d"))) <= BORDER):
        ans_days[today] = today

# 該当日数
print (len(ans_days))

# 該当率
print (len(ans_days)/len(target_days))

結果

今回の対象日数は0001年01月01日~9999年12月31日の3652059日間でした。その中で、2020年02月02日の様に2つ以下の数字で構成されている年月日は928日でした。全体に対するその確率は、0.0002541032332719707、つまり3935日に1回でした。なかなか、レアじゃないでしょうか。(かなりムラはありますが、10年に1度ペースですね。)ちなみに、以下の年月日が該当しました。(省略、抜粋しています。)

該当年月日の算出
for today in ans_days:
    print(ans_days[today].strftime("%Y/%m/%d"))
実行結果
0001年01月01日
0001年01月10日
0001年01月11日
(略)
2002年02月02日
2002年02月20日
2002年02月22日
2020年02月02日
2020年02月20日
2020年02月22日
2022年02月02日
2022年02月20日
2022年02月22日
2111年11月11日
2111年11月12日
2111年11月21日
(略)
9999年09月09日
9999年11月11日
9999年11月19日

前回は2002年02月22日、18年前ですね。2020年には2020年02月02日を含めて、3回あるようで、2022年にも3回あるようですね。その次は2111年……なかなか先ですね……

おわりに

本記事では、2020年02月02日のように、2つの数字のみで構成されている年月日を調査しました。2020年02月20日や2020年02月22日と近い日がありましたが、確率からいうと10年に1度程度と、レアでしたね。

というわけで(?)、2019年はありがとうございました。:bow:
2020年もよろしくお願いいたします。:bow:

(2019年1月2日追記)
以下の記事に掲載していただきました!ありがとうございます!

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?