Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by DavidJones
def safe_pawns(pawns):
"""
This was my first try :)
coords = []
for string in pawns:
coord = (int(string[0].replace(string[0],str(ord(string[0])-97))),int(string[1]))
coords.append(coord)
count = 0
#return coords
for coord in coords:
if (coord[0]+1,coord[1]-1) in coords or (coord[0]-1,coord[1]-1) in coords:
count += 1
return count"""
count = 0
for p in pawns:
if str(chr(ord(p[0])+1)+str(int(p[1])-1)) in pawns or \
str(chr(ord(p[0])-1)+str(int(p[1])-1)) in pawns:
count +=1
return count
Jan. 16, 2015