ゆゆ式版ツェラーの公式
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
# -*- coding:utf-8 -*- | |
""" | |
ゆゆ式版ツェラーの公式 | |
====================== | |
遊び方 | |
------ | |
$ python zeller.py 2013/11/11 | |
2013/11/11は月曜日 | |
""" | |
from __future__ import division | |
import math | |
import datetime | |
import time | |
def floor(x): | |
return int(math.floor(x)) | |
def h(y, m, d): | |
if (y, m, d) < (1582, 10, 15): | |
raise ValueError() | |
try: | |
datetime.date(y, m, d) | |
except: | |
raise ValueError() | |
if m == 1: | |
y -= 1 | |
m = 13 | |
elif m == 2: | |
y -= 1 | |
m = 14 | |
C = floor(y / 100) | |
Y = y % 100 | |
Gamma = 5 * C + floor(C / 4) | |
return (d + floor((26 * (m + 1)) / 10) + Y + floor(Y / 4) + Gamma) % 7 | |
def h_to_str(h): | |
return [u'土', u'日', u'月', u'火', u'水', u'木', u'金'][h] | |
def zeller(y, m, d): | |
print(u'{0}/{1}/{2}は{3}曜日'.format( | |
y, m, d, h_to_str(h(y, m, d)))) | |
def yuyushiki_zeller(y, m, d): | |
if (y, m, d) == (1999, 11, 11): | |
print(u'はい\nツェラーの公式を\n使えばわかりますな・・・') | |
return | |
if (y, m, d) == (2020, 1, 1): | |
print(u'うむ') | |
time.sleep(1) | |
print(u'それも\nツェラーの公式で\nわかりますな') | |
return | |
try: | |
w = h_to_str(h(y, m, d)) | |
except ValueError: | |
print(u'あ━━━━━━━う━━━━━━━…') | |
return | |
n = floor(d / 7) | |
if d % 7 != 0: | |
n += 1 | |
if w == u'木' and n == 2 or w == u'土' and n != 2: | |
print(u'ポテト') | |
return | |
print(u'{0}/{1}/{2}は{3}曜日'.format(y, m, d, w)) | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) != 2: | |
print(u'あ━━━━━━━う━━━━━━━…') | |
sys.exit(1) | |
try: | |
y, m, d = [int(x) for x in sys.argv[1].split('/')] | |
except: | |
print(u'あ━━━━━━━う━━━━━━━…') | |
sys.exit(1) | |
yuyushiki_zeller(y, m, d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment