def helper(origin,new_idxs): ''' 将list 按新的索引重排 ''' res=[] for new_idx in new_idxs: res.append(origin[new_idx-1]) return res def bfs(origin,target): ''' 判断两个骰子是否一样 ''' if origin ==target: return True visited =[origin] queue= [origin] choices=[ [1,2,6,5,3,4], #向左翻转90度 [6,5,3,4,1,2] #向下翻转90度 ] while queue: tmp=queue.pop(0) for choice in choices: res =helper(tmp,choice) if res ==target: return True if res not in visited: visited.append(res) queue.append(res) return False
全部评论
(1) 回帖