@@ -5,65 +5,147 @@ This is a community driven Java template and utility API for the annual [Advent
5
5
6
6
1 . Clone this repository from GitHub as an IntelliJ repository (untested on other IDE's)
7
7
2 . Add the ` AOC_SESSION_COOKIE ` environment variable to your gradle run config and set it equal to that of your session cookie after logging in to your AoC account.
8
+ * Alternatively you can set a system environment variable and restart the IDE/terminal.
8
9
3 . Execute the gradle application -> run task.
9
10
10
- # Creating and running a solution #
11
+ # Creating and Running Solutions #
11
12
13
+ ## Solution Packages
12
14
Create a ` package-info.java ` in the package which contains your solutions for a given year.
13
- Make sure to annotate it with the ` @AdventYear ` annotation.
14
- Example:
15
+ Make sure to annotate it with the ` @AdventYear ` annotation, so we can pull the correct inputs.
15
16
17
+ ** Example** :
16
18
``` java
17
19
@AdventYear (year = 2024 )
18
20
package org.togetherjava.aoc.solutions ;
21
+
19
22
import org.togetherjava.aoc.core.annotations.AdventYear ;
20
23
```
21
24
22
- Create an implementation of the ` PuzzleSolution ` interface and annotate it with the ` @AdventDay ` annotation
25
+ The package my contain any files or subpackages you wish, but as described next, the solutions need a specific structure.
23
26
24
- ``` java
25
- import org.togetherjava.aoc.core.annotations.AdventDay ;
26
- import org.togetherjava.aoc.core.puzzle.PuzzleInput ;
27
- import org.togetherjava.aoc.core.puzzle.PuzzleSolution ;
27
+ ---
28
+ ## Solution Classes
29
+ Solution implementations must be under an ` @AdventYear ` package to be runnable.
30
+ Additionally, they must implement the ` PuzzleSolution ` interface, which provides methods
31
+ that give an input type directly.
32
+
33
+ A useful shortcut for this is ` CTRL + I ` in IntelliJ, which implements missing methods.
34
+
35
+ ### Setting The Day
36
+
37
+ While ` @AdventYear ` explicitly defines the year, a solution can implicitly or explicitly
38
+ define which day of the year.
39
+
40
+ ### Explicit Day Value
41
+ To explicitly set which day your solution corresponds to, use the ` @AdventDay ` annotation to override and ignore auto-detection.
28
42
43
+ ** Example** :
44
+ ``` java
29
45
@AdventDay (day = 1 )
46
+ public class DayOne implements PuzzleSolution
47
+ ```
48
+
49
+ ### Implicit Day Auto -Detection
50
+ If no `@AdventDay ` annotation is provided, a default auto-detection is used instead.
51
+ This will look for the *first* number in the class name in the range `[1, 31]`, ignoring leading zeros.
52
+ Therefore , the following examples would be parsed as:
53
+
54
+ | Class Name | Implicit Day |
55
+ |----------------|--------------|
56
+ | `Day1 ` | 1 |
57
+ | `Day02 ` | 2 |
58
+ | `Day003 ` | 3 |
59
+ | `AocDay4 ` | 4 |
60
+ | `AocDay05 ` | 5 |
61
+ | `Aoc2024Day6 ` | 6 |
62
+ | `Aoc2024Day07 ` | 7 |
63
+ | `Day8Attempt2 ` | 8 |
64
+
65
+ ---
66
+ If neither implicit nor explicit days can be resolved, an error is thrown at runtime.
67
+
68
+ ### Puzzle Solution
69
+ The methods defined by `PuzzleSolution ` return `Object `, which is because not all
70
+ AOC answers are `int` or `long`. You may still return an `int` or `long` type, and it will be autoboxed into an object.
71
+
72
+ Here is an example implementation
73
+
74
+ ```java
30
75
public class Day01 implements PuzzleSolution {
31
76
32
77
@Override
33
78
public Object part1 (PuzzleInput input ) {
34
- return 0L ;
79
+ return 123 ;
35
80
}
36
81
37
82
@Override
38
83
public Object part2 (PuzzleInput input ) {
39
- return 0L ;
84
+ return 456L ;
40
85
}
41
86
}
42
87
```
43
88
44
- Then you can run your solutions with the static ` AocRunner ` class.
89
+ ## Running Solutions
90
+ The ` AocRunner ` class provides static access to run your solution implementations.
91
+
92
+ There are 3 method names: ` run ` , ` runPart1 ` , and ` runPart2 ` , which each have the following overrides:
93
+
94
+ | Parameters | Description |
95
+ | ------------------------------------------| ------------------------------|
96
+ | ` () ` | Run today |
97
+ | ` (int year, int day) ` | Run the given day |
98
+ | ` (PuzzleDate date) ` | Run the given date |
99
+ | ` (Class<? extends PuzzleSolution> impl) ` | Run the given implementation |
100
+
101
+
102
+ Below are examples of different runner invocations:
45
103
46
104
``` java
47
- AocRunner . run(); // this will detect and invoke the current day's problems
48
- AocRunner . run(2024 , 1 ); // this will detect and invoke a day for a given year/day
49
- AocRunner . run(Day01 . class); // Invoke a specific class
105
+ AocRunner . run(); // Detect and run the current day's solution
106
+ AocRunner . run(2024 , 1 ); // Detect and run the AOC 2024 Day 1 solution
107
+ AocRunner . run(Day01 . class); // Run the solution implemented in Day01
108
+ AocRunner . run(Day01BruteForce . class); // Run the solution implemented in Day01BruteForce
50
109
```
51
110
52
- # Getting your session cookie #
111
+ ### Multiple Solutions
112
+ If more than one class implements a solution for a given date, all of those
113
+ implementations are registered internally. When trying to run them without
114
+ a specific class reference (` e.g. run(Day1BruteForce.class) ` ) then the specific
115
+ implementation chosen is not well-defined, and is whichever is reflectively found first.
116
+
117
+ # Input Caching
118
+ Input files are fetched from the AOC web API to get your input data. To support AOC,
119
+ we automatically cache the input responses on your local computer, preventing redundant API
120
+ calls every time you run an implementation.
121
+
122
+ ## Local File Cache
123
+ Cached input files are stored locally in a path relative to your OS platform. This is done
124
+ with the ` user.home ` system property. Relative to that, ` /.together-java/aoc/inputs/YYYY-DD-puzzle-input.txt `
125
+ is where the file is stored.
126
+
127
+ * Windows: ` %userprofile%/.together-java/aoc/inputs/ `
128
+
129
+ # Session Cookie (` AOC_SESSION_COOKIE ` )
130
+ ## Getting your session cookie
53
131
54
132
In Chrome, or other Chromium browsers such as Opera, OperaGX etc
55
- 1 . Hit ctrl + shift + J to open up developer tools
133
+ 1 . Hit ` ctrl + shift + J ` to open up developer tools
56
134
2 . Navigate to the application tab
57
135
3 . Click cookies
58
136
4 . Copy the session cookie
59
137
60
138
![ ] ( /setup/4.png )
61
139
62
- # Modifiying Gradle run configuration #
63
- 1 . Go to your Gradle tasks and go to application -> run and right click to modify the run configurations
64
- ![ ] ( /setup/1.png )
65
- 2 . Click this box to add an environment variable
140
+ ## Modifiying Gradle run configuration / env
141
+ 1 . Go to your Gradle tool window
142
+ * ` Tasks `
143
+ * ` application `
144
+ * Right-click ` run ` → ` Modify Run Configuration... `
145
+
146
+ ![ ] ( /setup/1.png )
147
+ 2 . Click this box to add an environment variable
66
148
![ ] ( /setup/2.png )
67
- 3 . Name the environment variable ` AOC_SESSION_COOKIE ` and then paste the value of your session cookie from your browser in to the value box.
149
+ 3 . Name the environment variable ` AOC_SESSION_COOKIE ` and then paste the value of your session cookie from your browser in to the value box.
68
150
![ ] ( /setup/3.png )
69
- 4 . Hit okay and then execute the Gradle run task
151
+ 4 . Hit okay and then execute the Gradle ` run ` task
0 commit comments