-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC5b.m
70 lines (63 loc) · 2.01 KB
/
AoC5b.m
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
clear; clc; close all;
input = fileread('inputAoC5.txt'); %input který nám dal AoC skopírovaný do .txt souboru
inputByLine = regexp(input, '\n', 'split'); %použiju delimiter \n pro rozdělení dat na jednotlivé řádky
data = regexp(inputByLine, '[,>-]', 'split');
map = zeros(10000);
for i = 1:length(data)
x1 = str2double(data{i}(1))+1;
y1 = str2double(data{i}(2))+1;
x2 = str2double(data{i}(4))+1;
y2 = str2double(data{i}(5))+1;
if (x1 == x2)
if (x1 > x2)
temp = x2;
x2 = x1;
x1 = temp;
end
if (y1 > y2)
temp = y2;
y2 = y1;
y1 = temp;
end
map(y1:y2, x1) = map(y1:y2, x1) + 1;
elseif (y1 == y2)
if (x1 > x2)
temp = x2;
x2 = x1;
x1 = temp;
end
if (y1 > y2)
temp = y2;
y2 = y1;
y1 = temp;
end
map(y1, x1:x2) = map(y1, x1:x2) + 1;
elseif (x1 < x2 && y1 < y2)
j = y1;
for i = x1:x2
map(j, i) = map(j, i) + 1;
j = j + 1;
end
elseif (x1 < x2 && y1 > y2)
j = y1;
for i = x1:x2
map(j, i) = map(j, i) + 1;
j = j - 1;
end
elseif (x1 > x2 && y1 < y2)
j = y1;
for i = x1:-1:x2
map(j, i) = map(j, i) + 1;
j = j + 1;
end
elseif (x1 > x2 && y1 > y2)
j = y1;
for i = x1:-1:x2
map(j, i) = map(j, i) + 1;
j = j - 1;
end
end
end
sum(map(:) > 1)
%map(x, y) = map(x, y) + 1;
%str2double(data{1}(1)) %první x data