Skip to content

Instantly share code, notes, and snippets.

@dketov
Created March 21, 2017 12:18
Show Gist options
  • Save dketov/3d26f7f81c5414fcbd7f6af9bfe8f46d to your computer and use it in GitHub Desktop.
Save dketov/3d26f7f81c5414fcbd7f6af9bfe8f46d to your computer and use it in GitHub Desktop.
ship = 'd3d9'
badship = 'd3e7'
def check(ship):
x1, y1, x2, y2 = map(lambda (x,y): y(x), zip(ship, (ord,int,ord,int)))
return (
check_diagonal(x1, y1, x2, y2)
and check_border(x1, y1)
and check_border(x2, y2)
)
def check_border(x, y):
if ord('a') <= x <= ord('h') and 0 <= y <= 9:
return True
return False
def check_diagonal(x1, y1, x2, y2):
if x1 - x2 and y1 - y2:
print 'No diagonal placing allowed'
return False
return True
print check(ship)
print check(badship)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment