Repository navigation
Expand file tree
/
Copy pathday14.java
More file actions
52 lines (50 loc) · 1.54 KB
/
Copy pathday14.java
File metadata and controls
52 lines (50 loc) · 1.54 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
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
File file = new File("in.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String l = br.readLine();
br.close();
int[][] g = new int[200][1000];
int my = 0;
String[] c = l.split(" -> ");
for (int i = 0; i < c.length; i++) {
int[] coordinates = Arrays.stream(c[i].split(",")).mapToInt(Integer::parseInt).toArray();
int x = coordinates[0];
int y = coordinates[1];
int dx = coordinates[2];
int dy = coordinates[3];
g[y][x] = 1;
while (x != dx || y != dy) {
x += (x < dx) ? 1 : -1;
y += (y < dy) ? 1 : -1;
g[y][x] = 1;
}
my = Math.max(my, y);
my = Math.max(my, dy);
}
for (int ix = 0; ix < g[0].length; ix++) {
g[my + 2][ix] = 1;
}
int co = 0;
while (g[0][500] == 0) {
int x = 500;
int y = 0;
while (true) {
if (g[y + 1][x] == 0) {
} else if (g[y + 1][x - 1] == 0) {
x -= 1;
} else if (g[y + 1][x + 1] == 0) {
x += 1;
} else {
break;
}
y += 1;
}
co += 1;
g[y][x] = 1;
System.out.println(c);
}
}
}