Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by ceu9jo
def safe_pawns(pawns):
ret = 0
for p in pawns:
for q in pawns:
if isSafe(p,q):
ret += 1
break
return ret
def get2pos(place):
r1 = chr( ord(place[0]) + 1) + str(int(place[1]) - 1)
r2 = chr( ord(place[0]) - 1) + str(int(place[1]) - 1)
return [ r1,r2 ]
def isSafe(p1,p2):
pos = get2pos(p1)
if p2 in pos:
return True
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
Aug. 21, 2014