-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kévin Belellou
committed
Nov 20, 2024
1 parent
fc67447
commit b3427c3
Showing
11 changed files
with
343 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.belellou.kevin</groupId> | ||
<artifactId>advent-of-code</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>Advent of Code</name> | ||
<description>Personal repository to develop and store my answers to the incredible puzzles from adventofcode.com</description> | ||
<url>https://github.com/kevin-belellou/advent-of-code</url> | ||
|
||
<developers> | ||
<developer> | ||
<name>Kévin Belellou</name> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.17.0</version> | ||
</dependency> | ||
</dependencies> | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.belellou.kevin</groupId> | ||
<artifactId>advent-of-code</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>Advent of Code</name> | ||
<description>Personal repository to develop and store my answers to the incredible puzzles from adventofcode.com | ||
</description> | ||
<url>https://github.com/kevin-belellou/advent-of-code</url> | ||
|
||
<developers> | ||
<developer> | ||
<name>Kévin Belellou</name> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<!-- Dependency versions --> | ||
<commons-lang3.version>3.17.0</commons-lang3.version> | ||
<assertj.version>3.26.3</assertj.version> | ||
<junit.version>5.11.3</junit.version> | ||
|
||
<!-- Plugin versions --> | ||
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version> | ||
<maven-failsafe-plugin.version>3.3.1</maven-failsafe-plugin.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit</groupId> | ||
<artifactId>junit-bom</artifactId> | ||
<version>${junit.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${commons-lang3.version}</version> | ||
</dependency> | ||
|
||
<!-- Test scope --> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven-surefire-plugin.version}</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>${maven-failsafe-plugin.version}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/belellou/kevin/advent/generic/AbstractDaySolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.belellou.kevin.advent.generic; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
public abstract class AbstractDaySolver implements DaySolver { | ||
|
||
private static final String SEPARATOR = "/"; | ||
private static final String INPUT_FOLDER = "src/main/resources/"; | ||
private static final String INPUT_FILE_NAME = "/input.txt"; | ||
|
||
private final String input; | ||
|
||
protected AbstractDaySolver(Year year, Day day) { | ||
input = INPUT_FOLDER + year.toString() + SEPARATOR + day.toString() + INPUT_FILE_NAME; | ||
} | ||
|
||
private BufferedReader getReader() { | ||
try { | ||
FileReader fileReader = new FileReader(input); | ||
return new BufferedReader(fileReader); | ||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public int solveFirstStar() { | ||
try (BufferedReader reader = getReader()) { | ||
return doSolveFirstStar(reader); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public int solveSecondStar() { | ||
try (BufferedReader reader = getReader()) { | ||
return doSolveSecondStar(reader); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected abstract int doSolveFirstStar(BufferedReader reader) throws IOException; | ||
|
||
protected abstract int doSolveSecondStar(BufferedReader reader) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.belellou.kevin.advent.generic; | ||
|
||
public enum Day { | ||
|
||
DAY_1("1"), | ||
DAY_2("2"), | ||
DAY_3("3"), | ||
DAY_4("4"), | ||
DAY_5("5"), | ||
DAY_6("6"), | ||
DAY_7("7"), | ||
DAY_8("8"), | ||
DAY_9("9"), | ||
DAY_10("10"), | ||
DAY_11("11"), | ||
DAY_12("12"), | ||
DAY_13("13"), | ||
DAY_14("14"), | ||
DAY_15("15"), | ||
DAY_16("16"), | ||
DAY_17("17"), | ||
DAY_18("18"), | ||
DAY_19("19"), | ||
DAY_20("20"), | ||
DAY_21("21"), | ||
DAY_22("22"), | ||
DAY_23("23"), | ||
DAY_24("24"), | ||
DAY_25("25"); | ||
|
||
private final String day; | ||
|
||
Day(final String day) { | ||
this.day = day; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return day; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/belellou/kevin/advent/generic/DaySolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.belellou.kevin.advent.generic; | ||
|
||
public interface DaySolver { | ||
|
||
int solveFirstStar(); | ||
|
||
int solveSecondStar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.belellou.kevin.advent.generic; | ||
|
||
public enum Year { | ||
|
||
YEAR_2015("2015"), | ||
YEAR_2016("2016"), | ||
YEAR_2017("2017"), | ||
YEAR_2018("2018"), | ||
YEAR_2019("2019"), | ||
YEAR_2020("2020"), | ||
YEAR_2021("2021"), | ||
YEAR_2022("2022"), | ||
YEAR_2023("2023"), | ||
YEAR_2024("2024"); | ||
|
||
private final String year; | ||
|
||
Year(final String year) { | ||
this.year = year; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return year; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/belellou/kevin/advent/year2015/Day1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.belellou.kevin.advent.year2015; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import com.belellou.kevin.advent.generic.AbstractDaySolver; | ||
import com.belellou.kevin.advent.generic.Day; | ||
import com.belellou.kevin.advent.generic.Year; | ||
|
||
public class Day1 extends AbstractDaySolver { | ||
|
||
private static final int STARTING_FLOOR = 0; | ||
|
||
public Day1() { | ||
super(Year.YEAR_2015, Day.DAY_1); | ||
} | ||
|
||
@Override | ||
protected int doSolveFirstStar(BufferedReader reader) throws IOException { | ||
String line = reader.readLine(); | ||
|
||
int up = StringUtils.countMatches(line, "("); | ||
int down = StringUtils.countMatches(line, ")"); | ||
|
||
int final_floor = STARTING_FLOOR + up - down; | ||
System.out.println("Final floor is: " + final_floor); | ||
|
||
return final_floor; | ||
} | ||
|
||
@Override | ||
protected int doSolveSecondStar(BufferedReader reader) throws IOException { | ||
String line = reader.readLine(); | ||
|
||
int currentFloor = STARTING_FLOOR; | ||
for (int i = 0; true; i++) { | ||
char c = line.charAt(i); | ||
|
||
if (c == '(') { | ||
currentFloor++; | ||
} else if (c == ')') { | ||
currentFloor--; | ||
} else { | ||
throw new IllegalStateException("Unexpected character: " + c); | ||
} | ||
|
||
if (currentFloor == -1) { | ||
int basementPosition = i + 1; | ||
System.out.println("Basement entered a position " + basementPosition); | ||
return basementPosition; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
((((()(()(((((((()))(((()((((()())(())()(((()((((((()((()(()(((()(()((())))()((()()())))))))))()((((((())((()))(((((()(((((((((()()))((()(())()((())((()(()))((()))()))()(((((()(((()()))()())((()((((())()())()((((())()(()(()(((()(())(()(())(((((((())()()(((())(()(()(()(())))(()((((())((()))(((()(()()(((((()()(()(((()(((((())()))()((()(()))()((()((((())((((())(()(((())()()(()()()()()(())((((())((())(()()))()((((())))((((()())()((((())((()())((())(())(((((()((((()(((()((((())(()(((()()))()))((((((()((())()())))(((()(()))(()()(()(((()(()))((()()()())((()()()(((())())()())())())((()))(()(()))(((((()(()(())((()(())(())()((((()())()))((((())(())((())())((((()(((())(())((()()((((()((((((()(())()()(()(()()((((()))(())()())()))(())))(())))())()()(())(()))()((()(()(())()()))(()())))))(()))(()()))(())(((((()(()(()()((())()())))))((())())((())(()(())((()))(())(((()((((((((()()()(()))()()(((()))()((()()(())(())())()(()(())))(((((()(())(())(()))))())()))(()))()(()(((((((()((((())))())())())())()((((((((((((((()()((((((()()()())())()())())())(())(())))())((()())((()(()))))))()))))))))))))))))())((())((())()()))))))(((()((()(()()))((())(()()))()()())))(())))))))(()(((())))())()())))()()(())()))()(()))())((()()))))(()))))()))(()()(())))))))()(((()))))()(()))(())())))))()))((()))((()))())(())))))))))((((())()))()))()))())(())()()(())))())))(()())()))((()()(())))(())((((((()(())((()(((()(()()(())))()))))))()))()(()((()))()(()))(()(((())((((())())(())(()))))))))())))))))())())))))())))))()()(((())()(()))))))))())))))(())()()()))()))()))(()(())()()())())))))))())()(()(()))))()()()))))())(()))))()()))))()())))))(((())()()))(()))))))))))()()))))()()()))))(()())())()()())()(()))))()(()))(())))))))(((((())(())())()()))()()))(())))))()(()))))(())(()()))()())()))()))()))()))))())()()))())())))(()))(()))))))())()(((())()))))))))()))()())))())))())))()))))))))))()()))(()()))))))(())()(()))))())(()))))(()))))(()())))))())())()()))))())()))))))))(()))))()))))))()(()())))))))()))())))())))())))())))))))())(()()))))))(()())())))()())()))))))))))))))())))()(())))()))())()()(())(()()))(())))())()())(()(()(()))))())))))))))))())(()))()))()))))(())()())()())))))))))))()()))))))))))))())())))))(()())))))))))))())(())))()))))))))())())(()))()))(())))()))()()(())()))))))()((((())()))())())))))()))()))))((()())()))))())))(())))))))))))))))))()))))()()())()))()()))))())()))((()())))())))(()))(()())))))))()))()))))(())))))))(())))))())()()(()))())()))()()))))())()()))))())()))())))))))(()))))()())()))))))))(()))())))(()))()))))(())()))())())(())())())))))))((((())))))()))()))()())()(())))()))()))()())(()())()()(()())()))))())())))))(()))()))))())(()()(())))))(())()()((())())))))(())(())))))))())))))))))()(())))))))()())())())()(()))))))))(()))))))))())()()))()(()))))))()))))))())))))))(())))()()(())()())))))(((())))()((())()))())))(()()))())(())())))()(((()())))))()(()()())))()()(()()(()()))())()(()()()))())()()))()())(()))))())))))())))(())()()))))(()))))(())(()))(())))))()()))()))))())()))()()(())())))((()))())()))))))()()))))((()(()))))()()))))))())))))())(()((()())))))))))))()())())))()))(()))))))(()))(())()())))(()))))))))())()()()()))))(()())))))))((())))()))(()))(())(())()())()))))))))(())))())))(()))()()))(()()))(()))())))()(())))())((()((()(())))((())))()))))((((())())()())))(())))()))))))())(()()((())))())()(()())))))(()())()))())))))))((())())))))))(()(()))())()()(()()(((()(((()())))))()))))))()(())(()()((()()(())()()))())()())()))()())())())))))))(((())))))))()()))))))(((())()))(()()))(()()))))(()(()()((((())()())((()()))))(()(())))))()((()()()())()()((()((()()))(()))(((()()()))(((())))()(((())()))))))((()(())())))(()())(((((()(()))(()((()))(()())()))))(()(()))()(()))(())(((())(()()))))()()))(((()))))(()()()()))())))((()()()(())()))()))))()()))()))))))((((((()()()))))())((()()(((()))))(()(())(()()())())())))()(((()()))(())((())))(()))(()()()())((())())())(()))))()))()((()(())()(()()(())(()))(())()))(())(()))))(())(())())(()()(()((()()((())))((()))()((())))(((()()()()((((()))(()()))()()()(((())((())())(()()(()()()))()((())(())()))())(((()()(())))()((()()())()())(()(())())(((())(())())((())(())()(((()()))(())))((())(()())())(())((()()()((((((())))((()(((((())()))()))(())(()()))()))(())()()))(())((()()())()()(()))())()((())))()((()()())((((()())((())())())((()((()))()))((())((()()(()((()()(((())(()()))))((()((())()(((())(()((())())((())(()((((((())())()(()())()(())(((())((((((()(())(()((()()()((()()(()()()())))()()(((((()()))()((((((()))()(()(()(()(((()())((()))())()((()))(())))()))()()))())()()))())((((())(()(()))(((((((())(((()(((((()(((()()((((())(((())())))(()()()(()(()))()))((((((()))((()(((()(())((()((((()((((((())(((((())))(((()(()))))(((()(((())()((())(()((()))(((()()(((())((((()(()(((((()))(((()(((((((()(()()()(()(()(()()())(())(((((()(())())()())(()(()(()))()(()()()())(()()(()((()))()((())())()(()))((())(()))()(()))()(((()(()(()((((((()()()()())()(((((()()(((()()()((()(((((()))((((((((()()()(((((()))))))(()()()(())(()))(()()))))(())()))(((((()(((((()()(()(()())(((()))((((()((()(()(()((()(()((())))()(((()((()))((()))(((((((((()((()((()(())))()((((()((()()))((())(((()(((((()()(()(()()((()(()()()(((((((())())()())))))((((()()(()))()))(()((())()(()(((((((((()()(((()(()())(()((()())((())())((((()(((()(((()((((()((()((((()(()((((((())((((((((((((()()(()()((((((((((((((()((()()))()((((((((((((())((((()(()())((()(()(()))()(((((()()(((()()))()())(())((()(((((()((())(((((()((()(((((()))()()((((())()((((())(((((((((()(())(()(())))())(()((())(((())(())(())())(()(()(())()()((()((())()(((()(((((()(())))()(((()((())))((()()()(((()(((()((()(()(())(()((()())(()(()(((()(((((((((())(()((((()()))(()((((()()()()(((()((((((((()(()()((((((()(()()(()((()((((((((((()()(((((((()())(())))(((()()))(((((()((()()())(()()((((())((()((((()))))(())((()(()()(((()(()(((()((((()(((((()))())())(()((())()))(((()())((())((())((((()((()((((((())(()((((()()))((((((())()(()))((()(((())((((((((((()()(((((()(((((()((()()()((((())))(()))()((()(())()()((()((((((((((()((())(())(((((()(()(()()))((((()((((()()((()(((()(((((((((()(()((()((()))((((((()(((())()()((()(((((((()())))()()(()((()((()()(((()(()()()()((((()((())((((()(((((((((()(((()()(((()(()(((()(((()((())()(()((()(()(()(()))()(((()))(()((((()((())((((())((((((())(()))(()((((())((()(()((((((((()()((((((()(()(()()()(())((()((()()(((()(((((((()()((()(((((((()))(((((()(((()(()()()(()(((()((()()((())(()(((((((((()(()((()((((((()()((())()))(((((()((())()())()(((((((((((()))((((()()()()())(()()(()(()()))()))(()))(()(((()()))())(()(()))()()((())(()())()())()(()))()))(()()(()((((((())((()(((((((((((()(())()((()(()((()((()(()((()((((((((((()()())((())()(())))((())()())()(((((()(()())((((()((()(())(()))(((())()((()))(((((())(()))()()(()))(((())((((()((((()(())))(((((((()))))())()())(())((())()(()()((()(()))()(()()(()()((()())((())((()()))((((()))()()))(()()(())()()(((((()(())((()((((()))()))(()())())(((()()(()()))(())))))(()))((())(((((()((((()))()((((()))()((())(((())))(((()())))((()(()()(( |
20 changes: 20 additions & 0 deletions
20
src/test/java/com/belellou/kevin/advent/year2015/Day1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.belellou.kevin.advent.year2015; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class Day1Test { | ||
|
||
private static final Day1 DAY_1 = new Day1(); | ||
|
||
@Test | ||
public void testSolveFirstStar() { | ||
assertThat(DAY_1.solveFirstStar()).isEqualTo(74); | ||
} | ||
|
||
@Test | ||
public void testSolveSecondStar() { | ||
assertThat(DAY_1.solveSecondStar()).isEqualTo(1795); | ||
} | ||
} |