A project to get you started solving Advent of Code challenge in Java.
The Main
method in App
will execute the code for a given day based on input in src/main/resources/day[number].txt
The given Day
class will process the input and return a result, which App
will print to stdout
.
The shell for day 1 is already there. These are the steps to add day 2, etc. For day 1 you can start by writing the test cases once the puzzle posts.
src/main/java/aoc/day02/Day02.java
and make sure it implements Day
src/main/test/aoc/day02/Day02Test.java
and use the sample input/output from adventofcode.com to write tests (they will initially fail). Use Day01Test.java
as an example.Day02.part1()
until the tests pass (Test Driven Development!). You can run ./gradlew --continuous check
to have the tests run every time you save your code.src/main/resources/day02.txt
./gradlew run --args="2"
to get your output.
./gradlew run
.Day02Test.java
using the sample input/output from adventofcode.comDay02.part2()
until the tests pass../gradlew run --args="2 2"
to get your output.
If you are using VSCode, this project comes with a launch template that will prompt you for arguments. Enter just the day (to run part 1) or the day and part to run part 2.
3
4 2
If you want to run a day directly (e.g. run Day01.java
) you can just add a main
method to your Day01
class:
public static void main(String[] args) { App.runPart1ForDay(1); }
Call runPart1ForDay
for part 2. Make sure you specify the correct day number (1
in the example above)!
The App
calls defaultYear()
which defaults to the current year during December, and the previous year otherwise. If you want to use this starter to work on another year, just hard code the value of year
in App.main
to return the year you want.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4