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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| map1 = [0x1, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00]
def checkValid(theMap, x, y): if x < 0 or y < 0: return False if x > 9 or y > 8: return False return theMap[y * 10 + x] == 0
def isAllClear(theMap): return sum(theMap) == 90
def genNextValid(theMap, x, y): insList = [] if checkValid(theMap, x + 1, y): insList.append((1, x + 1, y))
if checkValid(theMap, x - 1, y): insList.append((4, x - 1, y))
if y % 2 == 0: if checkValid(theMap, x + 1, y + 1): insList.append((2, x + 1, y + 1)) if checkValid(theMap, x + 1, y - 1): insList.append((-1, x + 1, y - 1)) if checkValid(theMap, x, y + 1): insList.append((3, x, y + 1)) if checkValid(theMap, x, y - 1): insList.append((5, x, y - 1)) else: if checkValid(theMap, x, y + 1): insList.append((2, x, y + 1)) if checkValid(theMap, x, y - 1): insList.append((-1, x, y - 1)) if checkValid(theMap, x - 1, y + 1): insList.append((3, x - 1, y + 1)) if checkValid(theMap, x - 1, y - 1): insList.append((5, x - 1, y - 1)) return insList
def dfs(CurMap, curX, curY, InsList): CurMap = CurMap.copy() CurMap[curY * 10 + curX] = 1
if isAllClear(CurMap): print("Find Solve.") print(InsList) for y in range(9): line = '' for x in range(10): if CurMap[y * 10 + x] == 0: line = line + "." else: line = line + "#" print(line) return InsList
curInsList = genNextValid(CurMap, curX, curY) if len(curInsList) == 0: return None
result = None for i in curInsList: InsList.append(i) dfs(CurMap, i[1], i[2], InsList) InsList.pop() return result
dfs(map1, 0, 0, [])
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' target = [(1, 1, 0), (2, 2, 1), (3, 1, 2), (4, 0, 2), (3, 0, 3), (2, 0, 4), (1, 1, 4), (2, 2, 5), (3, 1, 6), (4, 0, 6), (3, 0, 7), (2, 0, 8), (1, 1, 8), (1, 2, 8), (-1, 3, 7), (1, 4, 7), (2, 4, 8), (1, 5, 8), (-1, 6, 7), (-1, 6, 6), (5, 6, 5), (-1, 6, 4), (5, 6, 3), (4, 5, 3), (3, 4, 4), (4, 3, 4), (5, 3, 3), (-1, 3, 2), (5, 3, 1), (-1, 3, 0), (1, 4, 0), (2, 5, 1), (1, 6, 1), (-1, 6, 0), (1, 7, 0), (2, 8, 1), (1, 9, 1), (2, 9, 2), (3, 9, 3), (4, 8, 3), (3, 7, 4), (2, 8, 5), (2, 8, 6), (3, 8, 7), (2, 8, 8), (1, 9, 8)] flagPos = 0 realPos = 0 v7 = 0 flag = '' for i in range(0, len(target), 2): step1 = target[i][0] step2 = target[i + 1][0] flagPos = i // 2
if step1 == -1: step1 = 0
if step2 == -1: step2 = 0
FindAns = None for idx in range(len(alpha)): v7 = (flagPos + idx // 6) % 6 v6 = 5 - (idx + flagPos) % 6 if v6 == step1 and v7 == step2: FindAns = idx
flag += alpha[FindAns] print(flag)
|