Sherlock Holmes Curious Lockbox Solver | Python

ThiccDaddyLOAF

March 12th, 2021 11:37:53 AM

					
import copy begining = [False,False,False,False,False,None,True,True,True,True,True] #False = black True = white its = [0] def swap(layout, step): layoutCopy = copy.deepcopy(layout) layoutCopy[(step[0]+step[1])], layoutCopy[step[1]] = layoutCopy[step[1]], layoutCopy[(step[0]+step[1])] return layoutCopy def isSolved(layout): for i in range(len(layout)): if(layout[i] == False): return (i >= (len(layout)/2)) def recurse(layout, its, steps = []): if isSolved(layout): its[0] += 1 print(layout,list(x[0] for x in steps)) return step = None for i in range(len(layout)): if(layout[i] == None): if(i >= 1): #If the empty space could have something to the left if(layout[i - 1] == False): step = [-1,i] recurse(swap(layout,step), its, (steps+[step])) if(i > 1): #If the empty space could have something 2 to the left if(layout[i - 2] == False): step = [-2,i] recurse(swap(layout,step), its, (steps+[step])) if(i < (len(layout)-1)): #If the empty space could have something to the right if(layout[i + 1] == True): step = [1,i] recurse(swap(layout,step), its, (steps+[step])) if(i < (len(layout)-2)): #If the empty space could have something to the right if(layout[i + 2] == True): step = [2,i] recurse(swap(layout,step), its, (steps+[step])) its[0] += 1 #return None recurse(begining,its,[]) print(its[0])

Featured Posts