Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions exercises/1000_programs/medium/1880_word_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def word_to_number(word: str) -> int:
num_str = ""
for ch in word:
num_str += str(ord(ch) - ord("a"))
return int(num_str)


def is_sum_equal(firstWord: str, secondWord: str, targetWord: str) -> bool:
return word_to_number(firstWord) + word_to_number(secondWord) == word_to_number(targetWord)


if __name__ == "__main__":
# Exemplos básicos para teste manual
print(is_sum_equal("acb", "cba", "cdb")) # True
print(is_sum_equal("aaa", "a", "aaaa")) # True
print(is_sum_equal("a", "b", "c")) # False