-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDay2.java
41 lines (34 loc) · 886 Bytes
/
Day2.java
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
package com.sbaars.adventofcode.year19.days;
import com.sbaars.adventofcode.year19.Day2019;
import com.sbaars.adventofcode.year19.intcode.IntcodeComputer;
public class Day2 extends Day2019 {
public Day2() {
super(2);
}
public static void main(String[] args) {
new Day2().printParts();
}
@Override
public Object part1() {
return execute(12, 2);
}
@Override
public Object part2() {
return bruteForceFindingNumber(19690720, 99);
}
private int bruteForceFindingNumber(int number, int bound) {
for (int i = 0; i < bound; i++) {
for (int j = 0; j < bound; j++) {
if (execute(i, j) == number) {
return 100 * i + j;
}
}
}
return -1;
}
private long execute(int x, int y) {
IntcodeComputer computer = new IntcodeComputer(2, x, y);
computer.run();
return computer.firstElement();
}
}