@LevMckinney/

descrambler

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from enum import Enum

class Moves(Enum):
  swap = 1
  shift = 2
  nothing = 3


def shift (l):
  return l[-1] + l[0:-1]

def swap (l):
  return l[-1] + l[1:-1] + l[0]

def findBestMove (scramble, target):
  d = 0
  while True:
    d = d + 1
    print(d)
    if explore(shift(scramble), target, False, 1, d):
      return Moves.shift
    elif explore(swap(scramble), target, True, 0, d):
      return Moves.swap
 

def explore(scramble, target, swaped, shifts, depth):
  if scramble == target:
    return True
  elif depth <= 0:
    return False
  elif swaped:
    return explore(shift(scramble), target, False, 1, depth - 1)
  elif shifts >= len(scramble) - 1:
    explore(swap(scramble), target, True, 0, depth - 1)
  else:
    return explore(swap(scramble), target, True, 0, depth - 1) or explore(shift(scramble), target, False, shifts + 1,depth - 1)

print(findBestMove("ourF","Four"))