• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Dec 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. '''
2. Group Members
3. =============
4. '''
5.
6. userids = ['Thormundur15'] # fill in this array with strings of usernames
7. def m3p1(L):
8.     '''Output the center of gravity for the List of tuples L
9.     '''
10.     xSum, ySum = 0, 0
11.     for p in L:
12.         for i in range(0, len(p)):
13.             if(i == 0):
14.                 xSum += p[i]
15.             else:
16.                 ySum += p[i]
17.     x = float(round((xSum / len(L)), 2))
18.     y = float(round((ySum / len(L)), 2))
19.     return (x, y)
20.
21. def m3p2(p,q):
22.     '''Calculate the Euclidean distance between p and q. As a float rounded to 2 decimal places
23.     '''
24.     x = p - q
25.     y = p - q
26.     x = x * x
27.     y = y * y
28.     Num = sqrt(x + y)
29.     return float(round(Num, 2))
30.
31. def m3p3(p,q):
32.     '''Calculate the Manhattan distance between p and q. As a float rounded to 2 decimal places
33.     '''
34.     x = p - q
35.     y = p - q
36.     if x < 0:
37.         x = -x
38.     if y < 0:
39.         y = -y
40.     return x + y
41.
42. def m3p4(sites, gridsize, B, f = 1/2, g = 1, d = m3p3):
43.     '''Write a function that implements Rossmo's equation. Note that we
44. give default values for the inputs f, g and d. The input sites should be a list
45. of sites of interest, gridsize is a tuple giving the size of the grid and B is an
46. integer giving the size of the buffer zone.
47.     '''
48.     Num = 0
49.     M = [[0 for _ in range(gridsize)] for _ in range(gridsize)]
50.     for i in range(0, gridsize):
51.         for j in range(0, gridsize):
52.             for s in sites:
53.                 if d((i,j), s) > B:
54.                     Num += 1 / (d((i,j), s)**f)
55.                 else:
56.                     Num += (B**(g-f)) / ((2*B - (d((i,j), s)))**g)
57.             M[i][j] = float(round(Num, 2))
58.             Num = 0
59.     return M
60.
61. def m3p5(sites, gridsize, B):
62.     '''Write a function m3p5(sites, gridsize, B) that finds a cell
63. (or cells) in the matrix m3p4(sites, gridsize, B) with the highest Rossmo value.
64.     '''
65.     M = m3p4(sites, gridsize, B)
66.     highVal = 0
67.     x, y = 0, 0
68.     for i in range(gridsize):
69.         for j in range(gridsize):
70.             if M[i][j] > highVal:
71.                 highVal = M[i][j]
72.     Ans = set()
73.     for i in range(gridsize):
74.         for j in range(gridsize):
75.             if M[i][j] == highVal:
77.     return Ans
78.
79. def m3p6(n=7):
80.     '''Write a function m3p6() that outputs the optimal stackings for player one of Kuhn poker.
81. Note that for testing purposes we need to be able to pass something as input. We use n=7.
82.     '''
83.     return ['KQJ']
84.
85. def m3p7(n=7):
86.     '''Write a function m3p7() that outputs the optimal stackings for player one
87. of K poker. Again, to avoid redundancy only list the cut of an optimal deck that starts with 2.
88. Note that for testing purposes we need to be able to pass something as input. We use n=7.
89.     '''
90.     return []
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top