Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active July 11, 2018 00:46
Show Gist options
  • Save doorbash/adb3e0257b7639e4e17353128a9b3d76 to your computer and use it in GitHub Desktop.
Save doorbash/adb3e0257b7639e4e17353128a9b3d76 to your computer and use it in GitHub Desktop.
import copy
width = 6
height = 5
list = [
[
[1, 0],
[0, 1],
[1, 1],
[2, 1]
],
[
[0, 0],
[0, 1],
[0, 2],
[1, 1]
],
[
[0, 0],
[1, 0],
[1, 1]
],
[
[0, 1],
[1, 0],
[1, 1],
[1, 2]
],
[
[0, 0],
[1, 0],
[0, 1],
[1, 1]
],
[
[0, 0],
[0, 1],
[1, 1],
[2, 1]
],
[
[0, 0],
[1, 0],
[0, 1]
],
[
[0, 0],
[1, 0],
[0, 1],
[2, 0]
]
]
def emal(mm, toUse, x, y):
for ll in list[toUse]:
mm[x + ll[0]][y + ll[1]] = 1
def foundIt(mm):
for i in range(0, width):
for j in range(0, height):
if mm[i][j] == 0:
return False
return True
def checkIfItsOk(mm, x, y, toUse):
for ll in list[toUse]:
if x + ll[0] >= width:
return False
if y + ll[1] >= height:
return False
if mm[x + ll[0]][y + ll[1]] == 1:
return False
return True
def findIt(mm, toUse):
ret = []
for i in range(0, width):
for j in range(0, height):
if checkIfItsOk(mm, i, j, toUse):
ret.append([i, j])
return ret
def f(mm, toUse, usedWhere):
l = findIt(mm, toUse)
found = False
for ll in l:
uw = copy.deepcopy(usedWhere)
uw.append([toUse, ll])
m = copy.deepcopy(mm)
emal(m, toUse, ll[0], ll[1])
if foundIt(m):
print("found it!")
print(uw)
return True
if toUse + 1 == len(list):
return False
if f(m, toUse + 1, uw):
found = True
return found
matrix = [[0 for y in range(height)] for x in range(width)]
if not f(matrix, 0, []):
print("Not Found!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment