python 3.x - permutations with two groups recursive -


i need kick in head on problem(https://uchicago.kattis.com/problems/uchicago.shortmanhattan). list code have written below. know looks terrible, can reach far. want present thinking problem.

def permunation_xy(x_move, y_move):     if len(x_move) == 0 , len(y_move) >= 1:         return y_move     elif len(y_move) == 0 , len(x_move) >= 1:         return x_move     elif len(x_move) == 0 , len(y_move) == 0:         return []      else:         [x_move[-1]] + permunation_xy(x_move[:-1], y_move)          [y_move[-1]] + permunation_xy(x_move, y_move[:-1])   x0, y0, x1, y1 = map(int, input().split()) x_move = [] y_move = [] if x0 == x1 , y0 == y1:     print("none") else:     dx = x1 - x0     dy = y1 - y0      if dx > 0:         x_move = ["right"] * abs(dx)     elif dx < 0:         x_move = ["left"] * abs(dx)     else:         x_move = []     if dy > 0:         y_move = ["up"] * abs(dy)     elif dy < 0:         y_move = ["down"] * abs(dy)     else:         y_move =[]      print(" ".join(permunation_xy(x_move, y_move))) 

in problem, how should build recursion process? how deal multi outputs? think problem looks building simple binary tree?

beyond problem, depressed recursive programming, don't know how think them, don't know how establish basic step, , recursive step. can share experience me? thank you!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

javascript - How to bind ViewModel Store to View? -

javascript - Solution fails to pass one test with large inputs? -