def moves_three(n, a=0, b=1, c=2):
    '''give a int -> return a list '''
    if n==1:
        return ((a,c),)
    return moves_three(n-1,a,c,b)+\
           ((a,c),)+\
           moves_three(n-1,b,a,c)

def moves(n, a=0, b=1, c=2):
    stack = [(True, n, a, b, c)]
    while stack:
        tag, n, a, b, c = stack.pop()
        print(tag, n, a, b, c)
        if n == 1:
            yield a, c
        elif tag:
            stack.append((False, n, a, b, c))
            stack.append((True, n-1, a, c, b))
        else:
            yield a, c
            stack.append((True, n-1, b, a, c))

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-08-05
  • 2021-04-21
相关资源
相似解决方案