From b57fd2b8573102c1e660c8dbccabe45e291b2261 Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Tue, 31 Mar 2020 23:44:34 +0200 Subject: [PATCH] Added script to calculate and priny all the triangles possible --- dreieck.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 dreieck.py diff --git a/dreieck.py b/dreieck.py new file mode 100644 index 0000000..8cad37e --- /dev/null +++ b/dreieck.py @@ -0,0 +1,47 @@ + +class Triangle(object): + def __init__(self, a, b, c): + self.a = a + self.b = b + self.c = c + + def check(self): + for x in range(1,self.a): + y = self.a - x + z = self.c - y + if False: + print(x, y, z) + print(self.a, x + y) + print(self.b, x + z) + print(self.c, y + z) + print('-----') + if self.b == x + z: + self.x = x + self.y = y + self.z = z + return True + return False + + +def print3(t): + print(' ▁▁▁▁▁▁▁▁▁▁▁') + print(' {0:3} ▏ {1:3} ▕ {2:3} '.format( t.a, t.x, t.b)) + print(' ▏{0:3} | {1:3}▕'.format(t.y, t.z)) + print(' ▔▔▔▔▔▔▔▔▔▔▔') + print(' {0:3}'.format(t.b)) + + +count_ex = 0 +count_ok = 0 +for a in range(1,101): + for b in range(1,101): + for c in range(1,101): + count_ex += 1 + t = Triangle(a, b, c) + if t.check(): + count_ok += 1 + print3(t) + +print(count_ex) +print(count_ok) +