Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a sample Code Challenge
- # Learn more: https://stepik.org/lesson/9173
- # Ask your questions via support@stepik.org
- def generate():
- return []
- class Robot():
- loc = 0
- dir = " "
- pre_loc = 0
- pre_dir = " "
- def __init__(self, loc, dir):
- self.loc = loc
- self.dir = dir
- #self.pre_loc = loc
- #self.pre_dir = dir
- def check(reply, clue):
- height = 8
- width = 8
- adj = [[-1, -1, 8, -1], [-1, 2, 9, -1], [-1, 3, 10, 1], [-1, -1, 11, 2], [-1, 5, 12, -1], [-1, 6, -1, 4],
- [-1, 7, -1, 5], [-1, -1, 15, 6], [0, -1, 16, -1], [1, 10, -1, -1], [2, -1, -1, 9], [3, -1, 19, -1],
- [4, 13, 20, -1], [-1, -1, -1, 12], [-1, 15, 22, -1], [7, -1, -1, 14], [8, 17, 24, -1], [-1, 18, -1, 16],
- [-1, 19, 26, 17], [11, -1, -1, 18], [12, -1, 28, -1], [-1, 22, 29, -1], [14, -1, 30, 21], [-1, -1, 31, -1],
- [16, -1, 32, -1], [-1, 26, 33, -1], [18, 27, 34, 25], [-1, 28, -1, 26], [20, 29, -1, 27], [21, 30, -1, 28],
- [22, -1, 38, 29], [23, -1, 39, -1], [24, -1, 40, -1], [25, 34, 41, -1], [26, 35, -1, 33], [-1, -1, 43, 34],
- [-1, 37, 44, -1], [-1, -1, 45, 36], [30, -1, 46, -1], [31, -1, 47, -1], [32, -1, 48, -1], [33, -1, -1, -1],
- [-1, -1, 50, -1], [35, -1, 51, -1], [36, -1, 52, -1], [37, -1, 53, -1], [38, -1, 54, -1], [39, -1, 55, -1],
- [40, 49, 56, -1], [-1, 50, -1, 48], [42, -1, -1, 49], [43, -1, 59, -1], [44, -1, -1, -1], [45, 54, 61, -1],
- [46, 55, 62, 53], [47, -1, 63, 54], [48, 57, -1, -1], [-1, 58, -1, 56], [-1, 59, -1, 57], [51, 60, -1, 58],
- [-1, 61, -1, 59], [53, -1, -1, 60], [54, 63, -1, -1], [55, -1, -1, 62]]
- N = 0
- DEBUGG = 0
- Robots = []
- input = []
- solution = []
- student_sol = []
- N = int(clue[0])
- reply = reply.splitlines()
- clue = clue.splitlines()
- for i in range(N):
- input.append(clue[i + 1].split())
- input[i][0] = int(input[i][0])
- input[i][1] = int(input[i][1])
- input[i][3] = int(input[i][3])
- input[i][4] = int(input[i][4])
- for i in range(N):
- solution.append(clue[1 + N + i])
- for i in range(len(reply)):
- student_sol.append(reply[i])
- for i in range(N):
- one_robot = Robot(input[i][0] + 8 * input[i][1], input[i][2])
- Robots.append(one_robot)
- Robots[i].loc = input[i][0] + 8 * input[i][1]
- Robots[i].dir = input[i][2]
- max_size = 0
- for i in range(len(student_sol)):
- if len(student_sol[i]) > max_size:
- max_size = len(student_sol[i])
- for i in range(max_size):
- if DEBUGG:
- print(i)
- for j in range(N):
- Robots[j].old_dir = (Robots[j].dir)
- Robots[j].old_loc = (Robots[j].loc)
- for j in range(N):
- if i >= len(student_sol[j]):
- continue
- if student_sol[j][i] == 'F':
- Robots[j].loc = adj[Robots[j].loc][intdir(Robots[j].dir)]
- if (student_sol[j][i] == 'R'):
- Robots[j].dir = chardir((intdir(Robots[j].dir) + 1) % 4)
- Robots[j].loc = adj[Robots[j].loc][intdir(Robots[j].dir)]
- if (student_sol[j][i] == 'L'):
- Robots[j].dir = chardir((intdir(Robots[j].dir) + 3) % 4)
- Robots[j].loc = adj[Robots[j].loc][intdir(Robots[j].dir)]
- for j in range(N):
- if (Robots[j].loc == -1):
- if DEBUGG : print ("onto wall", j," robot" , i , "step")
- return False
- for j in range(N):
- for z in range(j + 1, N):
- if (Robots[j].loc == Robots[z].loc):
- if (DEBUGG):
- print("in one place", j, z, "robots", i, "step")
- return False
- if (Robots[j].loc == Robots[z].pre_loc):
- if (Robots[j].dir != Robots[z].dir):
- if DEBUGG :
- print("on tail", j, z, "robots", i, "step")
- return False
- if (Robots[z].loc == Robots[j].pre_loc):
- if (Robots[z].dir != Robots[j].dir):
- if DEBUGG :
- print("on tail", z, j, "robots", i, "step")
- return False
- for j in range(N):
- if (Robots[j].loc != input[j][4] * 8 + input[j][3]):
- if (DEBUGG):
- print(j, Robots[j].loc, input[j][4] * 8 + input[j][3])
- return False
- if (DEBUGG):
- print("ok")
- len_of_correct_ans = 0
- len_of_student_ans = 0
- for i in range (N):
- len_of_correct_ans += len(solution[i])
- len_of_student_ans += len(student_sol[i])
- if (len_of_student_ans > len_of_correct_ans):
- return False
- return True
- def intdir(c):
- if (c == 'U'): return 0;
- if (c == 'R'): return 1;
- if (c == 'D'): return 2;
- if (c == 'L'): return 3;
- def chardir(c):
- if (c == 0): return 'U';
- if (c == 1): return 'R';
- if (c == 2): return 'D';
- if (c == 3): return 'L';
- from hashlib import sha1
- def solve(dataset):
- solver = {'5ff29d92f002cd222154312740a68907dfa06019': '3\n1 2 D 2 4\n2 2 D 2 3\n3 2 L 1 4\nRLFFFFLFFLFFL\nFFRRRFFFFLLLRFF\nRFLFLLLRRFRLRL', '9196a0c01b4078153158cdbbc8a9f29e15b6a8b3': '2\n6 7 U 0 2\n7 7 U 1 2\nFLLRFFFFRFFFF\nFLRFFFLLRFFRL', '5ccfc1856d77aab9a87f56ec1079ece70daa426b': '2\n0 0 D 2 5\n0 1 R 2 1\nFFFFFFLFL\nRFFFFFLFFLFFLRFRLFLL', 'f68bef09e6437e08ceca39dedc09ccb6e1d4243c': '2\n0 0 D 2 5\n0 2 U 0 0\nFFFFFFLFL\nRFRFRRRLLFRF', 'b15280a79fa6a9a419428e6e4bb9a543489e5f08': '3 \n1 1 U 4 2\n2 7 D 6 1\n2 5 L 6 0\nFRFRFRLLFFFLLLRR\nLFFLRLFFFF\nLRFRFFFRFRLFLFFRF', '9a22b75342011d347f327c0c81999f3900686be7': '3\n4 6 U 7 2\n4 4 U 7 3\n5 5 R 7 4\nFFRRFLFLFFF\nRRFLFRRRRLFF\nRLLFFFLLLRFFLLF', '207d292defe4615f105c2f30829fdcb0471fdd81': '3\n6 4 U 3 5\n7 1 D 7 0\n4 0 U 7 1\nFLFFFFLLFR\nRLFRFRFFRFF\nRFFR', '1615a81b757dfe51090d68044bd71f28145e60d5': '1\n0 0 D 7 7\nFFLFRLFFFRFFFL', 'f75a18c0f40fcddce4bcd56c5a3abb9da1d1f1d2': '2\n3 4 D 3 7\n3 7 U 3 4\nFFF\nLFFRFFFFRFRFL', '4bba076d3d22d536d140deaaf4619cfed364920f': '3\n4 6 U 5 5\n4 4 U 4 4\n5 5 R 4 6\nFFRRFFRFRFFLRRFFFRFFRR\nRRFFRFRFFLRRFFFRFFRRFL\nRFRFRFFLRRFFFRFFRRFLLF', 'dfe6dabbbcc022a4d765111ffd403b9b04aa291c': '3\n1 1 R 7 6\n2 0 U 7 7\n0 0 D 6 7\nFLRRFRLFLRFFLFLRF\nRRFRLLFFFRFFFL\nFFFFFFFLFFFFLRR'}
- message = "".join(dataset.split()[0:50])
- digest = str(sha1(message.encode("utf-8")).hexdigest())
- try:
- return str(solver[digest])
- except:
- return digest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement