-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPA3Graph.m
More file actions
99 lines (79 loc) · 1.67 KB
/
PA3Graph.m
File metadata and controls
99 lines (79 loc) · 1.67 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
clc;
clear all;
close all;
fid = fopen('porgat.txt', 'r');
tline = fgetl(fid);
nChar = 6486;
nBook = 12942;
Char = textscan(fid, '%d %s', nChar, 'Delimiter', '\n');
Char = Char{2};
Book = textscan(fid, '%d %s', nBook, 'Delimiter', '\n');
Book = Book{2};
fgetl(fid) %skip *EdgesList
A = zeros(nChar,nBook);
while ~feof(fid)
C = strsplit(fgetl(fid));
for i = 2:length(C)
row = str2num(C{1}); % character is always index 1
col = str2num(C{i})-nChar;
A(row, col) = 1; % bool is true
end
end
% sqrMatrix * Identity is A^1 which represents first degree
sqrMatrix = A * A';
smn = zeros(nChar, 1);
% Spider Man is char number 5306
for i = 1:6486
if sqrMatrix(i, 5306) ~= 0
smn(i, 1) = 1;
end
end
% sqrMatrix sqaured is A*A which represents second degree
smn2 = sqrMatrix * sqrMatrix;
for i = 1:6486
if smn2(i, 5306) ~= 0
if smn(i, 1) == 0
smn(i, 1) = 2;
end
end
end
% sqrMatrix cubed is A*A*A which represents third degree
smn3 = sqrMatrix * sqrMatrix * sqrMatrix;
for i = 1:6486
if smn3(i, 5306) ~= 0
if smn(i, 1) == 0
smn(i, 1) = 3;
end
end
end
numx0 = 0;
numx1 = 0;
numx2 = 0;
numx3 = 0;
for i = 1:6486
if smn(i, 1) == 0
numx0 = numx0 + 1;
end
if smn(i, 1) == 1
numx1 = numx1 + 1;
end
if smn(i, 1) == 2
numx2 = numx2 + 1;
end
if smn(i, 1) == 3
numx3 = numx3 + 1;
end
end
disp(numx0)
disp(numx1)
disp(numx2)
disp(numx3)
x = [0, 1, 2, 3];
y = [numx0, numx1, numx2, numx3];
bar(x,y)
for i = 1:6486/2
fprintf('%s, %d\n', Char{i}, smn(i));
end
for i = 6486/2:6486
fprintf('%s, %d\n', Char{i}, smn(i));
end