Skip to content

Commit 0547c06

Browse files
committed
2 parents 09e2537 + 631852a commit 0547c06

File tree

3 files changed

+333
-181
lines changed

3 files changed

+333
-181
lines changed

input23.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ sub g c
2929
jnz g 2
3030
jnz 1 3
3131
sub b -17
32-
jnz 1 -23
32+
jnz 1 -23

src/day23/Main.java

Lines changed: 130 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -9,196 +9,146 @@ public class Main {
99
static int speed = 0;
1010

1111
public static void main(String[] args) {
12-
ArrayList<String> lines = new ReadInputHelper(23).getLines();
13-
14-
HashMap<String, Long> list = new HashMap<>();
15-
list.put("a", 1l);
16-
list.put("b", 0l);
17-
list.put("c", 0l);
18-
list.put("d", 0l);
19-
list.put("e", 0l);
20-
list.put("f", 0l);
21-
list.put("g", 0l);
22-
list.put("h", 0l);
23-
24-
for (int i = 0; i < lines.size() && i > -1; i++) {
25-
try {
26-
Thread.sleep(Main.speed);
27-
} catch (InterruptedException e1) {
28-
// TODO Auto-generated catch block
29-
e1.printStackTrace();
30-
}
31-
System.out.print("Programcount: " + (i+1) + ", ");
32-
System.out.print(lines.get(i));
33-
34-
String[] temp = lines.get(i).split(" ");
35-
36-
switch (temp[0]) {
37-
case "set": {
38-
long value = 0;
39-
try {
40-
value = Long.parseLong(temp[2]);
41-
} catch (NumberFormatException e) {
42-
value = list.get(temp[2]);
43-
}
44-
list.put(temp[1], value);
45-
}
46-
break;
47-
case "sub": {
48-
long value = 0;
49-
try {
50-
value = Long.parseLong(temp[2]);
51-
} catch (NumberFormatException e) {
52-
value = list.get(temp[2]);
53-
}
54-
55-
long result = list.get(temp[1]) + value;
56-
System.out.print(", substracting: " + list.get(temp[1]) + " and " + value + " = " + result);
57-
list.put(temp[1], result);
58-
}
59-
break;
60-
case "mul": {
61-
long value = 0;
62-
try {
63-
value = Long.parseLong(temp[2]);
64-
} catch (NumberFormatException e) {
65-
value = list.get(temp[2]);
66-
}
67-
68-
long result = list.get(temp[1]) * value;
69-
list.put(temp[1], result);
70-
}
71-
break;
72-
case "jnz": {
73-
long value = 0;
74-
75-
try {
76-
value = Long.parseLong(temp[2]);
77-
} catch (NumberFormatException e) {
78-
value = list.get(temp[2]);
79-
}
80-
long threshold = 0;
81-
82-
try {
83-
threshold = Long.parseLong(temp[1]);
84-
} catch (NumberFormatException e) {
85-
threshold = list.get(temp[1]);
86-
}
87-
88-
if (threshold != 0)
89-
i += value - 1;
90-
else
91-
System.out.print(", skipping jump");
92-
}
93-
break;
94-
95-
default:
96-
System.out.println("Forgot: " + temp[0]);
97-
}
98-
System.out.println(", value of program: " + list.get(temp[1]));
99-
}
100-
101-
System.out.println(list.get("h"));
12+
// ArrayList<String> lines = new ReadInputHelper(23).getLines();
13+
//
14+
// HashMap<String, Long> list = new HashMap<>();
15+
// list.put("a", 0l);
16+
// list.put("b", 0l);
17+
// list.put("c", 0l);
18+
// list.put("d", 0l);
19+
// list.put("e", 0l);
20+
// list.put("f", 0l);
21+
// list.put("g", 0l);
22+
// list.put("h", 0l);
23+
//
24+
// int counter = 0;
25+
//
26+
// for (int i = 0; i < lines.size() && i > -1; i++) {
27+
// try {
28+
// Thread.sleep(Main.speed);
29+
// } catch (InterruptedException e1) {
30+
// e1.printStackTrace();
31+
// }
32+
//// System.out.print("Programcount: " + (i + 1) + ", ");
33+
//// System.out.print(lines.get(i));
34+
//
35+
// String[] temp = lines.get(i).split(" ");
36+
//
37+
// switch (temp[0]) {
38+
// case "set": {
39+
// long value = 0;
40+
// try {
41+
// value = Long.parseLong(temp[2]);
42+
// } catch (NumberFormatException e) {
43+
// value = list.get(temp[2]);
44+
// }
45+
// list.put(temp[1], value);
46+
// }
47+
// break;
48+
// case "sub": {
49+
// long value = 0;
50+
// try {
51+
// value = Long.parseLong(temp[2]);
52+
// } catch (NumberFormatException e) {
53+
// value = list.get(temp[2]);
54+
// }
55+
//
56+
// long result = list.get(temp[1]) - value;
57+
//// System.out.print(", substracting: " + list.get(temp[1]) + " and " +
58+
// value + " = " + result);
59+
// list.put(temp[1], result);
60+
// }
61+
// break;
62+
// case "mul": {
63+
// long value = 0;
64+
// try {
65+
// value = Long.parseLong(temp[2]);
66+
// } catch (NumberFormatException e) {
67+
// value = list.get(temp[2]);
68+
// }
69+
//
70+
// long result = list.get(temp[1]) * value;
71+
// list.put(temp[1], result);
72+
// counter++;
73+
// }
74+
// break;
75+
// case "jnz": {
76+
// long value = 0;
77+
//
78+
// try {
79+
// value = Long.parseLong(temp[2]);
80+
// } catch (NumberFormatException e) {
81+
// value = list.get(temp[2]);
82+
// }
83+
// long threshold = 0;
84+
//
85+
// try {
86+
// threshold = Long.parseLong(temp[1]);
87+
// } catch (NumberFormatException e) {
88+
// threshold = list.get(temp[1]);
89+
// }
90+
//
91+
// if (threshold != 0)
92+
// i += value - 1;
93+
//// else
94+
//// System.out.print(", skipping jump");
95+
// }
96+
// break;
97+
//
98+
// default:
99+
// System.out.println("Forgot: " + temp[0]);
100+
// }
101+
//// System.out.println(", value of program: " + list.get(temp[1]));
102+
// }
103+
//
104+
// System.out.println(counter);
105+
// System.out.println(list.get("h"));
106+
new Temp().work();
102107
}
108+
103109
}
104110

105-
class Program extends Thread {
106-
HashMap<String, Long> list = new HashMap<>();
107-
ArrayList<String> lines;
108-
boolean locked = false;
109-
int counter = 0;
111+
class Temp {
112+
void work() {
113+
long b = 81;
114+
long c = b;
115+
long a = 1;
116+
long f, d, e;
117+
long g, h = 0;
118+
119+
if (a != 0) {
120+
b *= 100;
121+
b -= -100000;
122+
c = b;
123+
c -= -17000;
124+
}
110125

111-
public Program(ArrayList<String> lines) {
112-
this.setDaemon(true);
113-
list.put("a", 0l);
114-
list.put("b", 0l);
115-
list.put("c", 0l);
116-
list.put("d", 0l);
117-
list.put("e", 0l);
118-
list.put("f", 0l);
119-
list.put("g", 0l);
120-
list.put("h", 0l);
121-
this.lines = lines;
122-
}
126+
while (true) {
127+
f = 1;
128+
d = 2;
129+
do {
130+
e = 2;
123131

124-
@Override
125-
public void run() {
126-
for (int i = 0; i < lines.size(); i++) {
127-
try {
128-
Thread.sleep(Main.speed);
129-
} catch (InterruptedException e1) {
130-
// TODO Auto-generated catch block
131-
e1.printStackTrace();
132-
}
133-
System.out.print("Program: ");
134-
System.out.print(lines.get(i));
132+
if ( b % d == 0)
133+
f = 0;
135134

136-
String[] temp = lines.get(i).split(" ");
135+
d -= -1;
136+
g = d;
137+
g -= b;
138+
} while (g != 0);
137139

138-
switch (temp[0]) {
139-
case "set": {
140-
long value = 0;
141-
try {
142-
value = Long.parseLong(temp[2]);
143-
} catch (NumberFormatException e) {
144-
value = list.get(temp[2]);
145-
}
146-
list.put(temp[1], value);
140+
if (f == 0) {
141+
h -= -1;
147142
}
148-
break;
149-
case "sub": {
150-
long value = 0;
151-
try {
152-
value = Long.parseLong(temp[2]);
153-
} catch (NumberFormatException e) {
154-
value = list.get(temp[2]);
155-
}
143+
g = b;
144+
g -= c;
156145

157-
long result = list.get(temp[1]) - value;
158-
list.put(temp[1], result);
159-
}
146+
if (g == 0) {
160147
break;
161-
case "mul": {
162-
long value = 0;
163-
try {
164-
value = Long.parseLong(temp[2]);
165-
} catch (NumberFormatException e) {
166-
value = list.get(temp[2]);
167-
}
168-
169-
counter++;
170-
long result = list.get(temp[1]) * value;
171-
list.put(temp[1], result);
148+
} else {
149+
b -= -17;
172150
}
173-
break;
174-
case "jnz": {
175-
long value = 0;
176-
177-
try {
178-
value = Long.parseLong(temp[2]);
179-
} catch (NumberFormatException e) {
180-
value = list.get(temp[2]);
181-
}
182-
long threshold = 0;
183-
184-
try {
185-
threshold = Long.parseLong(temp[1]);
186-
} catch (NumberFormatException e) {
187-
threshold = list.get(temp[1]);
188-
}
189-
190-
if (threshold != 0)
191-
i += value - 1;
192-
else
193-
System.out.print(", skipping jump");
194-
}
195-
break;
196-
197-
default:
198-
System.out.println("Forgot: " + temp[0]);
199-
}
200-
201-
System.out.println(counter);
202151
}
152+
System.out.println(h);
203153
}
204-
}
154+
}

0 commit comments

Comments
 (0)