Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Group Members
- =============
- '''
- userids = ['Thormundur15'] # fill in this array with strings of usernames
- def m3p1(L):
- '''Output the center of gravity for the List of tuples L
- '''
- xSum, ySum = 0, 0
- for p in L:
- for i in range(0, len(p)):
- if(i == 0):
- xSum += p[i]
- else:
- ySum += p[i]
- x = float(round((xSum / len(L)), 2))
- y = float(round((ySum / len(L)), 2))
- return (x, y)
- def m3p2(p,q):
- '''Calculate the Euclidean distance between p and q. As a float rounded to 2 decimal places
- '''
- x = p[0] - q[0]
- y = p[1] - q[1]
- x = x * x
- y = y * y
- Num = sqrt(x + y)
- return float(round(Num, 2))
- def m3p3(p,q):
- '''Calculate the Manhattan distance between p and q. As a float rounded to 2 decimal places
- '''
- x = p[0] - q[0]
- y = p[1] - q[1]
- if x < 0:
- x = -x
- if y < 0:
- y = -y
- return x + y
- def m3p4(sites, gridsize, B, f = 1/2, g = 1, d = m3p3):
- '''Write a function that implements Rossmo's equation. Note that we
- give default values for the inputs f, g and d. The input sites should be a list
- of sites of interest, gridsize is a tuple giving the size of the grid and B is an
- integer giving the size of the buffer zone.
- '''
- Num = 0
- M = [[0 for _ in range(gridsize[1])] for _ in range(gridsize[0])]
- for i in range(0, gridsize[0]):
- for j in range(0, gridsize[1]):
- for s in sites:
- if d((i,j), s) > B:
- Num += 1 / (d((i,j), s)**f)
- else:
- Num += (B**(g-f)) / ((2*B - (d((i,j), s)))**g)
- M[i][j] = float(round(Num, 2))
- Num = 0
- return M
- def m3p5(sites, gridsize, B):
- '''Write a function m3p5(sites, gridsize, B) that finds a cell
- (or cells) in the matrix m3p4(sites, gridsize, B) with the highest Rossmo value.
- '''
- M = m3p4(sites, gridsize, B)
- highVal = 0
- x, y = 0, 0
- for i in range(gridsize[0]):
- for j in range(gridsize[1]):
- if M[i][j] > highVal:
- highVal = M[i][j]
- Ans = set()
- for i in range(gridsize[0]):
- for j in range(gridsize[1]):
- if M[i][j] == highVal:
- Ans.add((i,j))
- return Ans
- def m3p6(n=7):
- '''Write a function m3p6() that outputs the optimal stackings for player one of Kuhn poker.
- Note that for testing purposes we need to be able to pass something as input. We use n=7.
- '''
- return ['KQJ']
- def m3p7(n=7):
- '''Write a function m3p7() that outputs the optimal stackings for player one
- of K poker. Again, to avoid redundancy only list the cut of an optimal deck that starts with 2.
- Note that for testing purposes we need to be able to pass something as input. We use n=7.
- '''
- return []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement