From 7b624de8e3e3637a07364f992c1d7e4185e4a872 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 11 Aug 2019 18:42:52 +0200 Subject: initial commit --- python/42-coded_triangle_numbers.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/42-coded_triangle_numbers.py (limited to 'python/42-coded_triangle_numbers.py') diff --git a/python/42-coded_triangle_numbers.py b/python/42-coded_triangle_numbers.py new file mode 100644 index 0000000..3a90945 --- /dev/null +++ b/python/42-coded_triangle_numbers.py @@ -0,0 +1,17 @@ +from helper.numbers import is_triangular + + +def letter_alph_ord(l): + return ord(l) - 64 + +def sum_letter_ord(word): + return sum([letter_alph_ord(l) for l in word]) + +counter = 0 +with open('helper/data/words.txt', 'r') as file: + words = [w[1:-1] for w in file.read().split(',')] + for w in words: + if is_triangular(sum_letter_ord(w)): + counter += 1 + +print(counter) -- cgit