aboutsummaryrefslogtreecommitdiff
path: root/challenge-132/abigail/python/ch-1.py
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-09-28 14:21:01 +0200
committerAbigail <abigail@abigail.be>2021-10-02 20:56:06 +0200
commitd6547d06f1cb3102611a7a7df3d5a720fa645194 (patch)
treeff30cb8f5162e20eb2538e453f201e8f1f002f23 /challenge-132/abigail/python/ch-1.py
parent4654113af779173d91d68a66b245b899325a3b05 (diff)
downloadperlweeklychallenge-club-d6547d06f1cb3102611a7a7df3d5a720fa645194.tar.gz
perlweeklychallenge-club-d6547d06f1cb3102611a7a7df3d5a720fa645194.tar.bz2
perlweeklychallenge-club-d6547d06f1cb3102611a7a7df3d5a720fa645194.zip
AWK, Bash, C, Lua, Node,js, Perl, Python, and Ruby solutions for week 132
Diffstat (limited to 'challenge-132/abigail/python/ch-1.py')
-rw-r--r--challenge-132/abigail/python/ch-1.py43
1 files changed, 43 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..0f70d519e4
--- /dev/null
+++ b/challenge-132/abigail/python/ch-1.py
@@ -0,0 +1,43 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import math
+import fileinput
+
+def _int (x):
+ if x < 0:
+ return math . ceil (x)
+ else:
+ return math . floor (x)
+
+
+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))