Battle of the letters
Pyth 145 97 bytes
=Y.d[,\A,25 25,\B,*TT5,\C,T*5T)Km=G@YdzJm=H@YdwW&KJMX0hG_smedH gKJ gJKI<hhK0=tK)I<hhJ0=tJ;?K1?J2Z
A little less naive than before.
Try it online!
Explanations:
Let's cut the program in several parts.
=Y.d[,\A,25 25,\B,*TT5,\C,T*5T)
,\A,25 25 Create this list: ['A', [25, 25]]
,\B,*TT5 Create this list: ['B', [100, 5]]
,\C,T*5T Create this list: ['C', [10, 50]]
.d[ ) From the three lists, create a dictionary whose keys are the letters, and values are the inner lists
=Y Assign to the variable Y
The dictionary Y
is: {'A': [25, 25], 'C': [10, 50], 'B': [100, 5]}
. Then:
Km=G@YdzJm=H@YdwMX0hG_smedH
m=G@Ydz For all letters in first input string, make a copy of Y[letter]. Make a list of all those values...
K ...and assign the list to the variable K
m=H@Ydw For all letters in second input string, make a copy of Y[letter]. Make a list of all those values...
J ...and assign the list to the variable J
MX0hG_smedH Create a function g which takes two lists of couples, and subtract the sum of the second elements of the couples of the second list from the first element of the first couple of the first list
At this point, K
is a list of couples that represents the first army. Each couple of this list is a letter of the army, and is (health, damage)
for that letter. J
is exactly the same, but for the second army. g
is a function which takes two armies, and deals the damage made by the second army to the first one. Now:
W&KJ gKJ gJKI<hhK0=tK)I<hhJ0=tJ;
W&KJ While K not empty and J not empty
gKJ Call g(K,J). That computes the damages to first army
gJK Call g(J,K). That computes the damages to second army
I<hhK0=tK) If the first army's first letter is dead, remove it
I<hhJ0=tJ If the second army's first letter is dead, remove it
; End of while loop
When the while loop is over, K
and J
have their final value. If they are both empty, it's a tie; otherwise the non-empty army win. That is handled by the last piece of code:
?K1?J2Z
?K1 If K non-empty, display 1. Else...
?J2 ...if J non-empty, display 2. Else...
Z ...display zero
That's it!
Haskell, 199 193 179 176 171 bytes
a!b=(t<$>a)?(t<$>b)
t v=[(5,5),(20,1),(2,10)]!!(fromEnum v-65)
m=sum.map snd
f=filter((>0).fst)
[]?[]=0
[]?_=2
_?[]=1
a@((c,d):e)?b@((h,i):j)=f((c-m b,d):e)?f((h-m a,i):j)
Try it online!
Small trick: divided all the army stats by 5.