Skip to content

Instantly share code, notes, and snippets.

@rorhug
Created February 22, 2014 18:56
Show Gist options
  • Save rorhug/9160080 to your computer and use it in GitHub Desktop.
Save rorhug/9160080 to your computer and use it in GitHub Desktop.
final 2014 q2
room_count = int(raw_input())
def tb(x):
return x == "*"
def get_room_in_bools():
height, width = [ int(y) for y in raw_input().split(" ") ]
return [ [ tb(x) for x in list(raw_input()) ] for y_axis in xrange(0, height) ]
room_grids = [get_room_in_bools() for x in xrange(0, room_count)]
def do_room(room):
x_len = len(room[0])
#XAxisDiff
xad = [ 0 for x in xrange(0, x_len) ]
for (y_index, x_axis) in enumerate(room):
for (x_index, tile) in enumerate(x_axis):
if((xad[x_index] == 0) and (tile)):
xad[x_index] = 1
elif(xad[x_index] == 1 and (not tile)):
xad[x_index] = 2
elif(xad[x_index] == 2 and (tile)):
return "NO"
y_len = len(room)
#YAxisDiff
yad = [ 0 for y in xrange(0, y_len) ]
for x_index in xrange(x_len):
for y_index in xrange(y_len):
if((yad[y_index] == 0) and room[y_index][x_index]):
yad[y_index] = 1
elif(yad[y_index] == 1 and (not room[y_index][x_index])):
yad[y_index] = 2
elif(yad[y_index] == 2 and room[y_index][x_index]):
return "NO"
return "YES"
for (i, room) in enumerate(room_grids):
# EACH ROOM
print("Room " + str(i + 1) + ": " + do_room(room))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment