Skip to content

Commit 5f05d23

Browse files
committed
Add docs, handle year directory
1 parent 08e245c commit 5f05d23

File tree

9 files changed

+30
-8
lines changed

9 files changed

+30
-8
lines changed

cmd/aoc-cli/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/pkg/errors"
1313

1414
"github.com/oleg-balunenko/advent-of-code/puzzles"
15-
_ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/day01"
15+
_ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/2019/day01"
1616
)
1717

1818
const (
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package day01 solves https://adventofcode.com/2019/day/1
12
package day01
23

34
import (
@@ -10,27 +11,27 @@ import (
1011
"github.com/oleg-balunenko/advent-of-code/puzzles"
1112
)
1213

13-
type solver struct {
14+
type solution struct {
1415
name string
1516
}
1617

1718
func init() {
1819
const puzzleName = "day01"
1920

20-
puzzles.Register(puzzleName, solver{
21+
puzzles.Register(puzzleName, solution{
2122
name: puzzleName,
2223
})
2324
}
2425

25-
func (s solver) Part1(input io.Reader) (string, error) {
26+
func (s solution) Part1(input io.Reader) (string, error) {
2627
return calc(input, calcPart1)
2728
}
2829

29-
func (s solver) Part2(input io.Reader) (string, error) {
30+
func (s solution) Part2(input io.Reader) (string, error) {
3031
return calc(input, calcPart2)
3132
}
3233

33-
func (s solver) Name() string {
34+
func (s solution) Name() string {
3435
return s.name
3536
}
3637

puzzles/solutions/day01/fuel_test.go renamed to puzzles/solutions/2019/day01/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func Test_solver_Part1(t *testing.T) {
215215
tt := tt
216216

217217
t.Run(tt.name, func(t *testing.T) {
218-
s := solver{
218+
s := solution{
219219
name: tt.fields.name,
220220
}
221221
input := readerFromFile(t, tt.args.inputPath)
@@ -265,7 +265,7 @@ func Test_solver_Part2(t *testing.T) {
265265
tt := tt
266266

267267
t.Run(tt.name, func(t *testing.T) {
268-
s := solver{
268+
s := solution{
269269
name: tt.fields.name,
270270
}
271271
input := readerFromFile(t, tt.args.inputPath)
File renamed without changes.
File renamed without changes.
File renamed without changes.

puzzles/solutions/doc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Package declares common interface for puzzle solutions and functionality for register and run them.
2+
package solutions
3+
4+
// Each solution should implement `Solver` interface, be implemented udnder separate package and contain `init()`
5+
// function that will register that solution in list of all solvers.
6+
7+
// type solver struct {
8+
// name string
9+
// }
10+
//
11+
// func init() {
12+
// const puzzleName = "day01"
13+
// puzzles.Register(puzzleName, solver{
14+
// name: puzzleName,
15+
// })
16+
// }
17+
18+
// Then to register solution in the list of all solutions: make a blank import of package with puzzle solution
19+
// at main.go
20+
//
21+
// _ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/day01"

0 commit comments

Comments
 (0)