-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay05.java
More file actions
102 lines (91 loc) · 3.93 KB
/
Day05.java
File metadata and controls
102 lines (91 loc) · 3.93 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
100
101
102
//part 1 (maybe one of my less pritty code)
package org.thehuglio;
import java.io.File;
import java.util.Arrays;
public class Main {
private static final Reader reader = new Reader(new File("data.txt"));
public static void main(String[] args) {
System.out.println(reader.data);
String[][] containers = creator();
for (String s : reader.data) {
String[] splited = s.split(" ");
int move = Integer.parseInt(splited[1]);
int from = Integer.parseInt(splited[3]) - 1;
int to = Integer.parseInt(splited[5]) - 1;
for (int i = 0; i < move; i++) {
StringBuilder s1 = new StringBuilder();
StringBuilder s2 = new StringBuilder();
String safe = containers[from][0];
for (int j = 1; j < containers[from].length;j++) {
s1.append(containers[from][j] + " ");
}
s2.append(safe + " ");
for (int j = 0; j < containers[to].length;j++) {
s2.append(containers[to][j] + " ");
}
containers[from] = s1.toString().split(" ");
containers[to] = s2.toString().split(" ");
}
}
System.out.println(Arrays.deepToString(containers));
}
private static String[][] creator() {
String[] row1 = {"N", "R", "J", "T", "Z", "B", "D", "F"};
String[] row2 = {"H", "J", "N", "S", "R"};
String[] row3 = {"Q", "F", "Z", "G", "J", "N", "R", "C"};
String[] row4 = {"Q", "T", "R", "G", "N", "V", "F"};
String[] row5 = {"F", "Q", "T", "L"};
String[] row6 = {"N", "G", "R", "B", "Z", "W", "C", "Q"};
String[] row7 = {"M", "H", "N", "S", "L", "C", "F"};
String[] row8 = {"J", "T", "M", "Q", "N", "D"};
String[] row9 = {"S", "G", "P"};
return new String[][]{row1, row2, row3, row4, row5, row6, row7, row8, row9};
}
}
//part 2
package org.thehuglio;
import java.io.File;
import java.util.Arrays;
public class Main {
private static final Reader reader = new Reader(new File("data.txt"));
public static void main(String[] args) {
System.out.println(reader.data);
String[][] containers = creator();
for (String s : reader.data) {
String[] splited = s.split(" ");
int move = Integer.parseInt(splited[1]);
int from = Integer.parseInt(splited[3]) - 1;
int to = Integer.parseInt(splited[5]) - 1;
StringBuilder s1 = new StringBuilder();
StringBuilder s2 = new StringBuilder();
StringBuilder safe = new StringBuilder();
for (int j = 0; j < move; j++) {
if (j < containers[from].length) {
safe.append(containers[from][j]).append(" ");
}
}
for (int j = move; j < containers[from].length;j++) {
s1.append(containers[from][j]).append(" ");
}
s2.append(safe);
for (int j = 0; j < containers[to].length;j++) {
s2.append(containers[to][j]).append(" ");
}
containers[from] = s1.toString().split(" ");
containers[to] = s2.toString().split(" ");
}
System.out.println(Arrays.deepToString(containers));
}
private static String[][] creator() {
String[] row1 = {"N", "R", "J", "T", "Z", "B", "D", "F"};
String[] row2 = {"H", "J", "N", "S", "R"};
String[] row3 = {"Q", "F", "Z", "G", "J", "N", "R", "C"};
String[] row4 = {"Q", "T", "R", "G", "N", "V", "F"};
String[] row5 = {"F", "Q", "T", "L"};
String[] row6 = {"N", "G", "R", "B", "Z", "W", "C", "Q"};
String[] row7 = {"M", "H", "N", "S", "L", "C", "F"};
String[] row8 = {"J", "T", "M", "Q", "N", "D"};
String[] row9 = {"S", "G", "P"};
return new String[][]{row1, row2, row3, row4, row5, row6, row7, row8, row9};
}
}