Skip to content

Commit 073d152

Browse files
committed
Solved day 1 part 1
1 parent 53fea8a commit 073d152

File tree

19 files changed

+131
-5
lines changed

19 files changed

+131
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To run all solutions, simply run `./gradlew run`. If you want to run the solutio
1919

2020
| Day | Part 1 | Part 2 |
2121
|---------|---------|---------|
22-
| 1 | ||
22+
| 1 | ||
2323
| 2 |||
2424
| 3 |||
2525
| 4 |||
@@ -44,6 +44,6 @@ To run all solutions, simply run `./gradlew run`. If you want to run the solutio
4444
| 23 |||
4545
| 24 |||
4646
| 25 |||
47-
| **SUM** | **0** | **0 ⭐** |
47+
| **SUM** | **1** | **0 ⭐** |
4848

49-
Total: 0
49+
Total: 1

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2015'
7-
version '0.0.2'
7+
version '0.0.3'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {
@@ -45,6 +45,10 @@ subprojects {
4545
}
4646

4747
dependencies {
48+
if(!'utils'.equals(project.name)) {
49+
implementation project(':utils')
50+
}
51+
4852
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
4953
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
5054
}

day01/src/main/java/de/havox_design/aoc2015/day01/MainClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class MainClass {
66
private static final Logger LOGGER = Logger.getLogger(MainClass.class.getName());
77

88
public static void main(String[] args) {
9-
LOGGER.info("Solution 1: 13");
9+
LOGGER.info("Solution 1: " + NotQuiteLisp.processTask1("day01.txt"));
1010
LOGGER.info("Solution 2: 23");
1111
}
1212
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package de.havox_design.aoc2015.day01;
2+
3+
import de.havox_design.aoc2015.utils.DataReader;
4+
5+
import java.util.List;
6+
7+
public class NotQuiteLisp {
8+
private final String input;
9+
10+
public NotQuiteLisp(String fileName) {
11+
input = readData(fileName).get(0);
12+
}
13+
14+
public static int processTask1(String fileName) {
15+
NotQuiteLisp instance = new NotQuiteLisp(fileName);
16+
return instance.processTask1();
17+
}
18+
19+
public int processTask1() {
20+
int currentFloor = 0;
21+
22+
for(char c : input.toCharArray()) {
23+
currentFloor += translateFloor(c);
24+
}
25+
26+
return currentFloor;
27+
}
28+
29+
private int translateFloor(char c) {
30+
if('(' == c) {
31+
return 1;
32+
} else if (')' == c) {
33+
return -1;
34+
}
35+
else {
36+
throw new IllegalArgumentException("Illegal character found.");
37+
}
38+
}
39+
40+
private List<String> readData(String fileName) {
41+
return DataReader.readData(fileName, MainClass.class);
42+
}
43+
}

day01/src/test/java/de/havox_design/aoc2015/day01/Day01Test.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package de.havox_design.aoc2015.day01;
22

3+
import org.junit.jupiter.api.Assertions;
34
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.jupiter.params.provider.MethodSource;
8+
9+
import java.util.stream.Stream;
410

511
class Day01Test {
612

@@ -9,4 +15,24 @@ class Day01Test {
915
void testMainClass() {
1016
MainClass.main(new String[0]);
1117
}
18+
19+
@ParameterizedTest
20+
@MethodSource("getDataForTask1")
21+
void testTask1(String fileName, int expectedFloor) {
22+
Assertions.assertEquals(expectedFloor, NotQuiteLisp.processTask1(fileName));
23+
}
24+
25+
private static Stream<Arguments> getDataForTask1() {
26+
return Stream.of(
27+
Arguments.of("task1sample1.txt", 0),
28+
Arguments.of("task1sample2.txt", 0),
29+
Arguments.of("task1sample3.txt", 3),
30+
Arguments.of("task1sample4.txt", 3),
31+
Arguments.of("task1sample5.txt", 3),
32+
Arguments.of("task1sample6.txt", -1),
33+
Arguments.of("task1sample7.txt", -1),
34+
Arguments.of("task1sample8.txt", -3),
35+
Arguments.of("task1sample9.txt", -3)
36+
);
37+
}
1238
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
()()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(((
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()(()(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
))(((((

0 commit comments

Comments
 (0)