Skip to content

Instantly share code, notes, and snippets.

@jaideepheer
Created October 25, 2018 11:03
Show Gist options
  • Save jaideepheer/95db88e2df9e0e34a84d2b44da32a159 to your computer and use it in GitHub Desktop.
Save jaideepheer/95db88e2df9e0e34a84d2b44da32a159 to your computer and use it in GitHub Desktop.
T = int(input())
while(T>0):
T-=1
inp = input()
prevRange = 0
dist = 55 # max dist. (=infinity) for first robot
collision = False
# iterate through input string
for c in inp:
if not(c is '.'):
# if dist. < minDist then collision
# where minDist = range of current point + range of prev. point
if dist < prevRange+int(c):
# collision
collision = True
break
else:
# no collision, make this prev. point and go on
prevRange = int(c)
# new point calc. dist. from here now
dist = 0
else:
# no robot/point here, increment distance
dist += 1
# print ans.
if collision:
print('unsafe')
else:
print('safe')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment