aboutsummaryrefslogtreecommitdiff
path: root/challenge-132/abigail/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-10-09 17:07:32 +0800
committer冯昶 <seaker@qq.com>2021-10-09 17:07:32 +0800
commit2bd4f4d95ef7c33d45b5a80e69fce40287039986 (patch)
treefe4e1606401037346acc4695c91cf2b3dedb2d18 /challenge-132/abigail/python/ch-1.py
parent036fe13fa017e7127944ac86f3bbb47c8d822973 (diff)
parent4cd8d62dd835b0e16e39aae2169896ec58796b51 (diff)
downloadperlweeklychallenge-club-2bd4f4d95ef7c33d45b5a80e69fce40287039986.tar.gz
perlweeklychallenge-club-2bd4f4d95ef7c33d45b5a80e69fce40287039986.tar.bz2
perlweeklychallenge-club-2bd4f4d95ef7c33d45b5a80e69fce40287039986.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-132/abigail/python/ch-1.py')
-rw-r--r--challenge-132/abigail/python/ch-1.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-132/abigail/python/ch-1.py b/challenge-132/abigail/python/ch-1.py
new file mode 100644
index 0000000000..e8f339af2b
--- /dev/null
+++ b/challenge-132/abigail/python/ch-1.py
@@ -0,0 +1,35 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+def g2j (Y, M, D):
+ return (int ((1461 * (Y + 4800 + int ((M - 14) / 12))) / 4) +
+ int ((367 * (M - 2 - 12 * int ((M - 14) / 12))) / 12) -
+ int ((3 * int (((Y + 4900 + int ((M - 14) / 12)) / 100))) / 4) +
+ D - 32075)
+
+def j2g (J):
+ e = 4 * (J + 1401 + int (int ((4 * J + 274277) / 146097) * 3 / 4) - 38) + 3
+ D = int (((5 * (int ((e % 1461) / 4)) + 2) % 153) / 5) + 1
+ M = ((int ((5 * (int ((e % 1461) / 4)) + 2) / 153) + 2) % 12) + 1
+ Y = int (e / 1461) - 4716 + int ((12 + 2 - M) / 12)
+ return Y, M, D
+
+julian_today = g2j (2021, 9, 22)
+
+
+for line in fileinput . input ():
+ Y, M, D = map (lambda x: int (x), line . strip () . split ("/"))
+ julian_then = g2j (Y, M, D)
+ Y1, M1, D1 = j2g (2 * julian_then - julian_today)
+ Y2, M2, D2 = j2g (2 * julian_today - julian_then)
+ print ('{:04d}/{:02d}/{:02d}, {:04d}/{:02d}/{:02d}' .
+ format (Y1, M1, D1, Y2, M2, D2))