-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
67 lines (55 loc) · 1.66 KB
/
Copy pathfunctions.py
File metadata and controls
67 lines (55 loc) · 1.66 KB
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
import math
import pizza
def biggestViableSlice(x, y, puzza):
found=0
if puzza.remT>puzza.remM:
bestVal=float('Inf')
else:
bestVal=0
for h in xrange(puzza.H, 2*puzza.L, -1):
for (n, m) in findRects(h):
print n, m
# Check if its within the borders of the grid
if(x+n-1 < puzza.R and y+m-1 < puzza.C):
sslice = pizza.Slice(x, x+n-1, y, y+m-1)
ratio=ViableSlice(puzza.grid, sslice, puzza.L, puzza.H)
if ratio>0:
found=1
if puzza.remT>puzza.remM:
if bestVal>ratio:
bestVal=ratio
bestSlice=sslice
else:
if bestVal<ratio:
bestVal=ratio
bestSlice=sslice
if found:
return bestSlice
return None
def ViableSlice(grid, slice, L, H):
# count the number of elements in slice
count = 0
nt = 0
nm = 0
for i in range(slice.top, slice.bottom+1):
for j in range(slice.left, slice.right+1):
if grid[i][j] == 'M':
nm += 1
elif grid[i][j] == 'X':
return False
else:
nt += 1
if (count > H):
return 0
if not (nm >= L and nt >= L):
return 0
return float(nm)/nt
def findRects(H):
mylist = []
for x in range(1, int(math.sqrt(H)) + 1):
if(H % x == 0):
y = H/x
mylist.append((x, y))
if(x is not y):
mylist.append((y, x))
return mylist