Created
July 30, 2014 15:34
-
-
Save SlayterDev/afc90561326ef2d25e4d to your computer and use it in GitHub Desktop.
Get the word root of two strings and see who wins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def main(): | |
| strings = raw_input("Enter two comma seperated stings: ") | |
| strings = strings.split(',') | |
| origStrings = strings | |
| root1 = getWordRoot(strings[0]) | |
| root2 = getWordRoot(strings[1]) | |
| while (root1 == root2) and (len(strings[0]) > 1 and len(strings[1]) > 1): | |
| strings[0] = strings[0][:-1] | |
| strings[1] = strings[1][:-1] | |
| root1 = getWordRoot(strings[0]) | |
| root2 = getWordRoot(strings[1]) | |
| if root1 > root2: | |
| print(origStrings[0] + " wins!") | |
| elif root2 > root1: | |
| print(origStrings[1] + " wins!") | |
| else: | |
| if (len(strings[0]) > 1 or len(strings[1]) > 1): | |
| if (len(strings[0]) > len(strings[1])): | |
| print(origStrings[0] + " wins!") | |
| else: | |
| print(origStrings[1] + " wins!") | |
| else: | |
| print("STALEMATE") | |
| def getWordRoot(word): | |
| wordSum = 0 | |
| for ch in word: | |
| wordSum += ord(ch) - ord('A') + 1 | |
| while wordSum >= 10: | |
| temp = wordSum / 10; | |
| wordSum = (wordSum - (temp * 10)) + temp | |
| return wordSum | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment