homework2.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Задача Тьюринг"""
  2. array = []
  3. # array = [
  4. # [r,r,d,l],
  5. # [u,r,d,l],
  6. # [d,d,r,l],
  7. # [l,d,r,l]
  8. # ]
  9. while True:
  10. try:
  11. array.append(list(input()))
  12. except EOFError:
  13. break
  14. def find_cicle() -> str:
  15. index = []
  16. current_point = (0, 0)
  17. x = y = 0
  18. while current_point not in index:
  19. index.append(current_point)
  20. if array[y][x] == "r":
  21. if x + 1 > (len(array) - 1):
  22. current_point = (y, 0)
  23. else:
  24. current_point = (y, x + 1)
  25. y, x = current_point
  26. elif array[y][x] == "l":
  27. if x - 1 < 0:
  28. current_point = (y, (len(array) - 1))
  29. else:
  30. current_point = (y, x - 1)
  31. y, x = current_point
  32. elif array[y][x] == "u":
  33. if y - 1 < 0:
  34. current_point = ((len(array) - 1), x)
  35. else:
  36. current_point = (y - 1, x)
  37. y, x = current_point
  38. elif array[y][x] == "d":
  39. if y + 1 > (len(array) - 1):
  40. current_point = (0, x)
  41. else:
  42. current_point = (y + 1, x)
  43. y, x = current_point
  44. return f"{current_point[1]} {current_point[0]}"
  45. print(find_cicle())