MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_042/solution42.py:23–43  ·  view source on GitHub ↗

Finds the amount of triangular words in the words file. >>> solution() 162

()

Source from the content-addressed store, hash-verified

21
22
23def solution():
24 """
25 Finds the amount of triangular words in the words file.
26
27 >>> solution()
28 162
29 """
30 script_dir = os.path.dirname(os.path.realpath(__file__))
31 words_file_path = os.path.join(script_dir, "words.txt")
32
33 words = ""
34 with open(words_file_path) as f:
35 words = f.readline()
36
37 words = [word.strip('"') for word in words.strip("\r\n").split(",")]
38 words = [
39 word
40 for word in [sum(ord(x) - 64 for x in word) for word in words]
41 if word in TRIANGULAR_NUMBERS
42 ]
43 return len(words)
44
45
46if __name__ == "__main__":

Callers 1

solution42.pyFile · 0.70

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected