about summary refs log tree commit diff
path: root/THT/B/QG-2016/trigrid.py
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-03 10:15:35 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-03 10:15:35 +0700
commit28e15738638435ce5797b519d5ad1a8e7c8db5e8 (patch)
treeb919045e907c615e480544eb52bc0c5aada7c78c /THT/B/QG-2016/trigrid.py
parent198642ad1b4faf8c86041043aee0f30dc941e8e0 (diff)
downloadcp-28e15738638435ce5797b519d5ad1a8e7c8db5e8.tar.gz
THT/B/QG-2016: Add remainder.py
Diffstat (limited to 'THT/B/QG-2016/trigrid.py')
-rwxr-xr-xTHT/B/QG-2016/trigrid.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/THT/B/QG-2016/trigrid.py b/THT/B/QG-2016/trigrid.py
index ea33d07..0911ef9 100755
--- a/THT/B/QG-2016/trigrid.py
+++ b/THT/B/QG-2016/trigrid.py
@@ -1,10 +1,11 @@
 #!/usr/bin/env python3
 
-a = (4, 3, 5, 6, 111, 222, 3333, 4444, 55555, 666666, 7777777, 88888888,
-     999999999, 123456789123456789, 1000000000000000000)
+TESTS = (4, 3, 5, 6, 111, 222, 3333, 4444, 55555, 666666, 7777777, 88888888,
+         999999999, 123456789123456789, 1000000000000000000)
 
-t = lambda n: n * (n + 2) * (n * 2 + 1) // 8 % 2016
+# Fomular from http://mathworld.wolfram.com/TriangleTiling.html
+n = lambda a: a * (a + 2) * (a * 2 + 1) // 8 % 2016
 
 with open('TRIGRID.TXT', 'w') as f:
-    for i in a:
-        f.write("{}\n".format(t(i)))
+    for a in TESTS:
+        f.write("{}\n".format(n(a)))