Skip to content

Commit

Permalink
added graphs and code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChimiSeanGa committed May 19, 2017
1 parent 6b21a7c commit 6a9e0cb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions graph1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
4
0 1 0 1
1 0 1 1
0 1 0 1
1 1 1 0
1 0 -1 0
Dimension of matrix:
10 changes: 10 additions & 0 deletions graph2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
8
0 1 0 1 1 0 0 0
1 0 1 0 0 1 0 0
0 1 0 1 0 0 1 0
1 0 1 0 0 0 0 1
1 0 0 0 0 1 0 1
0 1 0 0 1 0 1 0
0 0 1 0 0 1 0 1
0 0 0 1 1 0 1 0
0 -1 0 1 0 -1 0 1
7 changes: 7 additions & 0 deletions graph3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
5
0 1 1 0 0
1 0 1 1 0
1 1 0 0 1
0 1 0 0 1
0 0 1 1 0
1 0 0 -0.5 -0.5
39 changes: 39 additions & 0 deletions mingraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

def getMatrix():
dim = int(raw_input())
mat = []

for col in range(dim):
row = [int(x) for x in raw_input().split()]
if len(row) != dim:
print('Invalid row')
return
mat.append(row)

return mat

def getWeights():
return [float(x) for x in raw_input().split()]

def calcScore(matrix, weights):
distSum = 0
for i in range(len(matrix)):
for j in range(i, len(matrix)):
if matrix[i][j] == 1:
distSum += (weights[i] - weights[j])**2

weightSum = 0.0
for i in range(len(weights)):
weightSum += weights[i]**2

return distSum / weightSum

def main():
matrix = getMatrix()
weights = getWeights()
score = calcScore(matrix, weights)
print('Your score is ' + str(score))

if __name__ == '__main__':
main()

0 comments on commit 6a9e0cb

Please sign in to comment.