Skip to content

Commit

Permalink
add README.md (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
thermoweb committed Mar 13, 2024
1 parent 5f47396 commit 4237b0d
Show file tree
Hide file tree
Showing 25 changed files with 988 additions and 246 deletions.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build
on:
push:
branches: [ main ]
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Fetch sources
uses: actions/checkout@v4
- name: Set up jdk 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: maven
- name: build with maven
run: ./mvnw --batch-mode --update-snapshots verify
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 🎄 Advent of Code {year}
Your solutions for [Advent of Code](https://adventofcode.com/) written in Java ☕.
## Template setup
### Configure repository
1. Open [the template repository](https://github.com/thermoweb/aoc-java-template) on GitHub
2. Click [Use this template](https://github.com/thermoweb/aoc-java-template/generate) and create your repository
3. Clone your repository on your computer

### Requirements
- Java 17+ installed

## Usage

```shell
Usage: aoc [COMMAND]
run Advent of Code command line tool.
Commands:
scaffold create class and tests for the day.
download download input file and create an empty example file.
solve run the solution with the input for the specified day.
help Display help information about the specified command.
```

The usual workflow of this is to:
1. use the `scaffold --day <day>` command to create both test and solution classes in the project for the day.
2. use the `download --day <day>` command to download the input of the day and create an empty example file.
3. write your solution
4. use the `solve --day <day>` command to launch your code with the day's input.

### Scaffold a day
This will create both day class and the associated test.
```shell
# example: `./aoc scaffold --day 1`
./aoc scaffold --day <day>
```

### Download Input for a day

> [!IMPORTANT]
> This requires in your home folder the file `.adventofcode.session` with your session-cookie in it.
> To find it, you have to log in on [adventofcode.com](https://adventofcode.com) and use the web developer tool to retrieve the value of the `session` cookie.
```shell
# example: `./aoc download --day 1`
./aoc download --day <day>
```

this will create the input file and download corresponding data of day and an empty example file.

### Solve a day
```shell
# example: `./aoc solve --day 1`
./aoc solve --day <day>
```
This will launch the day solver for the specified day with the input.

### Help
You can run the help command to see all available commands:
```shell
./aoc help
```

You also can have more information on commands with:
```shell
# example: `./aoc help solve`
./aoc help <command>
```

---

Inspired by [advent-of-code-rust](https://github.com/fspoettel/advent-of-code-rust) template.
20 changes: 20 additions & 0 deletions aoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

COMMAND=$1
AOC_JAR=${SCRIPT_DIR}/aoc-runner/target/aoc.jar

if [ ${COMMAND} == "solve" ] || [ ! -f ${AOC_JAR} ]
then
echo "building project jars"
./mvnw --batch-mode --quiet clean install
fi

if [ ${COMMAND} == "" ]
then
java -jar ${AOC_JAR} help
exit 1
fi

echo "launching aoc command '$@'"
java -jar ${AOC_JAR} $@
7 changes: 7 additions & 0 deletions aoc-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
31 changes: 19 additions & 12 deletions aoc-common/src/main/java/org/thermoweb/aoc/DayRunner.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.thermoweb.aoc;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DayRunner {

private static final Logger logger = LoggerFactory.getLogger(DayRunner.class);

private DayRunner() {

}
Expand All @@ -21,16 +26,18 @@ public static void runDay(Day dayToRun, int day) throws IOException {
}

public static String getInput(int day) throws IOException {
return getFileContent("../inputs/input_" + (day > 9 ? day : "0" + day) + ".txt");
return getResourceContent("inputs/input_" + (day > 9 ? day : "0" + day) + ".txt");
}

public static String getExample(int day) throws IOException {
return getFileContent("../examples/example_" + (day > 9 ? day : "0" + day) + ".txt");
return getResourceContent("examples/example_" + (day > 9 ? day : "0" + day) + ".txt");
}

public static String getFileContent(String filename) throws IOException {
try (Stream<String> lines = Files.lines(Path.of(filename))) {
return lines.collect(Collectors.joining("\n"));
public static String getResourceContent(String resourceName) throws IOException {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
try (InputStreamReader isr = new InputStreamReader(Objects.requireNonNull(classloader.getResourceAsStream(resourceName)));
BufferedReader reader = new BufferedReader(isr)) {
return reader.lines().collect(Collectors.joining("\n"));
}
}

Expand All @@ -39,9 +46,9 @@ private static void runPartOne(Day dayToRun, String input) {
long start = System.nanoTime();
Optional<BigInteger> result = dayToRun.partOne(input);
long end = System.nanoTime();
System.out.println("part 1: " + result.map(BigInteger::toString).orElse("<None>") + " (" + (end - start) / 1000000 + " ms)");
logger.info("part 1: {} ({}) ms", result.map(BigInteger::toString).orElse("<None>"), (end - start) / 1000000);
} catch (Exception e) {
System.out.println("exception occured in part 1!");
logger.atError().log("exception occurred in part 1!");
}
}

Expand All @@ -50,9 +57,9 @@ private static void runPartTwo(Day dayToRun, String input) {
long start = System.nanoTime();
Optional<BigInteger> result = dayToRun.partTwo(input);
long end = System.nanoTime();
System.out.println("part 2: " + result.map(BigInteger::toString).orElse("<None>") + " (" + (end - start) / 1000000 + " ms)");
logger.info("part 2: {} ({}) ms", result.map(BigInteger::toString).orElse("<None>"), (end - start) / 1000000);
} catch (Exception e) {
System.out.println("exception occured in part 1!");
logger.atError().log("exception occurred in part 2!");
}
}
}
65 changes: 0 additions & 65 deletions aoc-maven-plugin/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4237b0d

Please sign in to comment.