We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 3014a86 + 1bc0def commit 2621fa8Copy full SHA for 2621fa8
1 file changed
exercises/1000_programs/medium/1880_word_sum.py
@@ -0,0 +1,16 @@
1
+def word_to_number(word: str) -> int:
2
+ num_str = ""
3
+ for ch in word:
4
+ num_str += str(ord(ch) - ord("a"))
5
+ return int(num_str)
6
+
7
8
+def is_sum_equal(firstWord: str, secondWord: str, targetWord: str) -> bool:
9
+ return word_to_number(firstWord) + word_to_number(secondWord) == word_to_number(targetWord)
10
11
12
+if __name__ == "__main__":
13
+ # Exemplos básicos para teste manual
14
+ print(is_sum_equal("acb", "cba", "cdb")) # True
15
+ print(is_sum_equal("aaa", "a", "aaaa")) # True
16
+ print(is_sum_equal("a", "b", "c")) # False
0 commit comments