Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 04fc235

Browse files
committed
day 2 completed
1 parent 74a9f3c commit 04fc235

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

resources/Day2Inputs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,1,19,5,23,1,6,23,27,1,27,5,31,2,31,10,35,2,35,6,39,1,39,5,43,2,43,9,47,1,47,6,51,1,13,51,55,2,9,55,59,1,59,13,63,1,6,63,67,2,67,10,71,1,9,71,75,2,75,6,79,1,79,5,83,1,83,5,87,2,9,87,91,2,9,91,95,1,95,10,99,1,9,99,103,2,103,6,107,2,9,107,111,1,111,5,115,2,6,115,119,1,5,119,123,1,123,2,127,1,127,9,0,99,2,0,14,0

src/com/togetherjava/adventofcode/Day1.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static void main(String[] args) {
1313
double part2 = input.get().map(Day1::recursiveCalculateFuel).reduce(0D, Double::sum);
1414
System.out.println("Part 1 answer: " + part1);
1515
System.out.println("Part 2 answer: " + part2);
16-
1716
}
1817

1918
public static double recursiveCalculateFuel(double mass) {
@@ -27,4 +26,4 @@ public static double recursiveCalculateFuel(double mass) {
2726
public static double calculateFuel(double mass) {
2827
return Math.floor(mass / 3.0) - 2;
2928
}
30-
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.togetherjava.adventofcode;
2+
3+
import java.util.Arrays;
4+
5+
import com.togetherjava.adventofcode.util.ResourceLoader;
6+
7+
public class Day2 {
8+
9+
public static void main(String[] args) {
10+
String[] input = ResourceLoader.getInput("Day2Inputs.txt").get(0).split(",");
11+
int[] data = new int[input.length];
12+
for (int i = 0; i < data.length; i++) {
13+
data[i] = Integer.parseInt(input[i]);
14+
}
15+
data[1] = 12;
16+
data[2] = 2;
17+
int i = 0;
18+
while (i < data.length) {
19+
int opcode = data[i];
20+
if (opcode == 1) {
21+
int aPosition = data[i + 1];
22+
int bPosition = data[i + 2];
23+
int positionToStore = data[i + 3];
24+
int a = data[aPosition];
25+
int b = data[bPosition];
26+
data[positionToStore] = a + b;
27+
i += 4;
28+
} else if (opcode == 2) {
29+
int aPosition = data[i + 1];
30+
int bPosition = data[i + 2];
31+
int positionToStore = data[i + 3];
32+
int a = data[aPosition];
33+
int b = data[bPosition];
34+
data[positionToStore] = a * b;
35+
i += 4;
36+
} else if (opcode == 99) {
37+
System.out.println("Opcode 99 reached - terminating");
38+
break;
39+
}
40+
}
41+
System.out.println(Arrays.toString(data).replaceAll(" ", ""));
42+
System.out.println("Number at position 0 is " + data[0]);
43+
}
44+
}

0 commit comments

Comments
 (0)