My Word can beat up your Word
J, 100
z=:"."0@":@(+/)^:9@(64-~a.i.])@(#~' '&i.)"1
f=:*@-/"2@(z@((]#~]i.~{.@\:~)"1^:([:=/z))){'STALEMATE'&,
runs like this:
f 'NO',:'ZOO'
NO
f 'CAN',:'BAT'
CAN
f 'FAT',:'BANANA'
FAT
f 'ONE',:'ONE'
STALEMATE
it doesn't yet accept input exactly as asked.
APL (Dyalog) (91 86)
⎕ML←3⋄{Z≡∪Z←{2>⍴⍕⍵:⍵⋄∇+/⍎¨⍕⍵}¨+/¨⎕A∘⍳¨⍵:G[↑⍒Z]⋄1∊↑¨⍴¨⍵:'STALEMATE'⋄∇1∘↓¨⍵}G←Z⊂⍨','≠Z←⍞
Explanation (in order of execution):
⎕ML←3
: set ML to 3 (this makes⊂
mean partition, among other things).G←Z⊂⍨','≠Z←⍞
: read input, separate by commas, store in G and pass to the function.+/¨⎕A∘⍳¨⍵
: calculate the score for each word. (⎕A
is a list containing the alphabet.)Z←{2>⍴⍕⍵:⍵⋄∇+/⍎¨⍕⍵}¨
: calculate the digital root for each score (by summing all digits as long as there is still more than one digit) and store them in Z.Z≡∪Z
: if all scores are unique...:G[↑⍒Z]
: ...then output the word with the highest score (from the original list).⋄1∊↑¨⍴¨⍵:'STALEMATE'
: otherwise (if there's a tie), if one of the words is of length 1, output STALEMATE.⋄∇1∘↓¨⍵
: otherwise, take the first letter off each word and run the function again.
Ruby - 210
d,e=(a,b=$<.read.chop.split(/,/)).map{|w|w.bytes.sort}
r=->w,o=65{n=0;w.map{|c|n+=c-o};n>9?r[n.to_s.bytes,48]:n}
d.pop&e.pop while r[d]==r[e]&&d[1]&&e[1]
$><<[[:STALEMATE,a,b][a.size<=>b.size],a,b][r[d]<=>r[e]]
Tests:
$ ruby1.9 1128.rb <<< CAN,BAT
CAN
$ ruby1.9 1128.rb <<< ZOO,NO
NO
$ ruby1.9 1128.rb <<< ZOO,ZOO
STALEMATE