26
4
PROBLEM
Given two words, find the winner in a digital root battle.
Define the digital root of a word this way:
- Each letter of the alphabet is assigned a number: A = 1, B = 2, C = 3, ..., Z = 26
- Add the values for each letter to total the word. Take "CAT", for example. C+A+T = 3+1+20 = 24
- Add all the single digits that make up that result: 24 => 2 + 4 = 6
- Repeat step #3 until you reach a single digit. That single digit is the digital root of the word.
Rules:
- A winner is declared if its digital root is larger than the other.
- If the digital root values are equal, shorten the words by removing every instance of the highest value letter from both words and recalculating.
- Repeat steps #1 and #2 until there is a winner or one of the words has only a single letter (or no letters) remaining.
- If the digital root values are equal after going through the shortening process, the longer word is declared the winner.
- If the words are of equal length and no winner is found after going through the shortening process, no winner is declared.
Special rules:
- No use of modulus is allowed in the calculation of the digital root itself. It can be used anywhere else.
- Assume words will consist only of uppercase letters - no punctuation, no spaces, etc.
INPUT
Pull the words in through stdin (comma-separated). method parameters, or however you want. Make it clear in your solution or the code how the words are parsed or prepared.
OUTPUT
Display the winning word. If there is no winner, display "STALEMATE".
Examples:
intput: CAN,BAT
CAN = 18 = 9
BAT = 23 = 5
output: CAN
intput: ZOO,NO
ZOO = 56 = 11 = 2
NO = 29 = 11 = 2
OO = 30 = 3
N = 14 = 5
output: NO
UPDATE: Input must be read using stdin with the words as a comma-separated string.
UPDATE: Added a couple examples to test against.
UPDATE: clarified the removal of the highest valued letter in the case of a tie - this also alters slightly the stop condition as well - if a word is one letter or zero letters long, the shortening process is stopped

I couldn't be bothered to put this on EVERY entry, so here's a tip for anyone who sees this: if you have "-64" anywhere in your code to convert ascii codes, you can save yourself a character and make it "-1", since that's what it will work out to anyway! – Johno – 13 years ago
You should decide on the input, not leave it to choice, as it makes a huge difference in the programs. By picking an input method, and specing it, you remove "creative interpretations", and make a challenge that is equal for all. – MtnViewMark – 15 years ago
@MtnViewMark - Understood, but effectively I'm trying to remove the reading of the input from the character count. I'm not interested in the most clever or shortest way to read in the two words. Requiring a specific method also handicaps certain languages - I guess I'm just trying to get at the meat of the problem. – Steve – 15 years ago
1@Steve - Then you shouldn't specify the output as "display" either, yes? However, I think you are perhaps eliminating too much from the problem. A clever and short golf often stems from combining different aspects of the problem in tricky ways, for example folding some of the processing into the input or output. As for handicapping languages -- pretty much all of them can read stdin and write stdout. – MtnViewMark – 15 years ago
@MtnViewMark - Fair point. I'll make a simple update and clear it up. My language of choice just has a lengthy way of reading from stdin, so I get biased. :) – Steve – 15 years ago
Does taking the input an argument to main count as being from stdin? Oh, and generally, if you want to keep the requirements down on stray stuff like reading from stdin and having to import or include other modules or files, making the puzzle require a function rather than a whole program would probbaly be the best way to go. – Jonathan M Davis – 15 years ago
It would probably be a good idea to add some examples too, so that there are values to test against. – Jonathan M Davis – 15 years ago
@Jonathan - That was my intent without explicitly stating it (requiring a function/method) - my fault. I'll be clearer next time. For now, assume a full program is required. I also added some simple examples to test against. – Steve – 15 years ago
Oh. floccinaucinihilipilification – Martin York – 15 years ago
@Steve: If the word
BANANAties another word, does it becomeBAANAorBAAA? – Eelvex – 15 years ago@Eelvex - my intent was that it becomes "BAAA" - post should have read "by removing every instance of the highest value letter". – Steve – 15 years ago
It would really help to see a more comprehensive set of test vectors. In particular, it would be good to have test vectors that prove that code is correctly shortening BANANA to BAAA, not BAANA (as I thought you meant prior to your clarification). I wonder how many submitted solutions get that right - since it complicates things significantly (which is fine, just subtle). – MtnViewMark – 15 years ago
The problem never states that only two words will be supplied; is this given? Oh, and Rules #2/#3 are the suck :) – Phrogz – 15 years ago
Would subtracting nine from the total value until it's less than ten be considered "using a modulus"? – supercat – 12 years ago