-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlphabetWarAirstrike.py
41 lines (38 loc) · 1.44 KB
/
AlphabetWarAirstrike.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env python3
"""
Codewars Challenge - Alphabet War, Airstrike (6 kyu)
This function takes a string of letters and * symbols as inputs. 8 selected
letters (shown below in two dictionaries) have score values for either Left or
Right. Each * character in the string represents a bomb dropped on the letters
in the string and will eliminate the characters adjacent to the bomb character.
The remaining letters with score values for Left or Right then fight. The
function returns the winner if there is one and returns another message if there
was no winner.
"""
def alphabet_war(fight):
left_side = {'w':4,'p':3,'b':2,'s':1}
right_side = {'m':4,'q':3,'d':2,'z':1}
fight_list = list(fight)
left_score = 0
right_score = 0
for i in range(len(fight_list)-1):
if fight_list[i] == '*':
if fight_list[i-1] != '*' and i > 0:
fight_list[i-1] = 0
if fight_list[i+1] != '*' and i < (len(fight_list)-1):
fight_list[i+1] = 0
fight_list[i] = 0
if fight_list[-1] == '*':
fight_list[-2] = 0
fight_list[-1] = 0
for i in fight_list:
if i in right_side:
right_score += right_side[i]
if i in left_side:
left_score += left_side[i]
if right_score > left_score:
return ("Right side wins!")
elif left_score > right_score:
return ("Left side wins!")
else:
return ("Let's fight again!")