Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- move_names = "RLUDFB"
- def allow_adjacent_moves(move1, move2):
- idx1 = move_names.index(move1[0])
- idx2 = move_names.index(move2[0])
- if idx1 // 2 != idx2 // 2:
- # moves are on different axis
- return True
- if idx1 % 2 == 0 and idx2 % 2 == 1:
- # moves are on same axis, but different and in correct order (RL, but not LR)
- return True
- return False
- def recursive_gen(target_length, moves):
- if len(moves) == target_length:
- yield moves
- return
- for move_name in move_names:
- if moves and not allow_adjacent_moves(moves[-1], move_name):
- continue
- for count in ("", "2", "'"):
- moves.append(move_name + count)
- yield from recursive_gen(target_length, moves)
- moves.pop()
- if __name__ == '__main__':
- for alg in recursive_gen(3, []):
- print(' '.join(alg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement