-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05a.m
More file actions
executable file
·25 lines (25 loc) · 772 Bytes
/
05a.m
File metadata and controls
executable file
·25 lines (25 loc) · 772 Bytes
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
#!/usr/bin/octave -qf
t=cputime();
fid=fopen('05.txt', 'r');
data=fscanf(fid, '%d , %d -> %d , %d');
fclose(fid);
for i=1:500 vent{i}=reshape(data((1+(i-1)*4):(4*i)), 1, 4); endfor
crossings=zeros(1000,1000);
for i=1:500
a(1:4)=vent{i};
dirh=sign(a(3)-a(1));
dirv=sign(a(4)-a(2));
if (dirh==0)
for j=a(2):dirv:a(4)
++crossings(a(1),j);
endfor
elseif (dirv==0)
for j=a(1):dirh:a(3)
++crossings(j,a(2));
endfor
endif
endfor
crossings(crossings==1)=0;
crossings(crossings>=1)=1;
fprintf('There are %d points where more than one vent crosses.\n', sum(crossings(:)));
fprintf('This took %d seconds.\n', cputime()-t);