about summary refs log tree commit diff
path: root/others/other/hcn.py
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-20 15:11:08 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-20 15:11:08 +0700
commit4ac65940e064c5b587699549a0c7277d2dd733a8 (patch)
treee2a6052f5f3dcd56e760ed85b13310147aeea42b /others/other/hcn.py
parenta0c92beee1199f13227b1642ccf07f264912e5ad (diff)
downloadcp-4ac65940e064c5b587699549a0c7277d2dd733a8.tar.gz
Thầy Nguyễn Thanh Tùng ôn THT XXIII
Diffstat (limited to 'others/other/hcn.py')
-rwxr-xr-xothers/other/hcn.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/others/other/hcn.py b/others/other/hcn.py
new file mode 100755
index 0000000..6b2fa2b
--- /dev/null
+++ b/others/other/hcn.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+from collections import deque
+
+
+def not_square(A, B, C):
+    """Return False is ABC is a square angle, True otherwise."""
+    return (B[0]-A[0])*(B[0]-C[0]) + (B[1]-A[1])*(B[1]-C[1])
+
+
+def parallelogram_last_point(A, B, C):
+    """Return the (x, y) coordinates of the point D of the parallelogram
+    ABCD.
+    """
+    return A[0] - B[0] + C[0], A[1] - B[1] + C[1]
+
+
+with open('hcn.inp') as fi, open('hcn.out', 'w') as fo:
+    d = deque(tuple(map(int, line.split())) for line in fi.readlines())
+    while not_square(*d): d.rotate()
+    print(*parallelogram_last_point(*d), file=fo)