Skip to content

Commit a474842

Browse files
committed
Update documentation for new puzzzle generation
1 parent f3b1895 commit a474842

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,48 @@ It is possible to generate a new file for your next puzzle using the following c
5050
$ make next
5151
```
5252

53-
After this, it's up to you to solve the puzzle. I would recommend something like the following when you figure out the answer:
53+
After this, it's up to you to solve the puzzle. The thing that's just been generated will look a little like this:
54+
```go
55+
func Puzzle001() Puzzle {
56+
// In this function, you can add large strings (your input data, perhaps) so
57+
// that they can be parsed in the initialisation phase of the puzzle and won't
58+
// count to the time taken for your algorithm.
59+
data := `1
60+
2
61+
3`
62+
63+
// You can add multiple variables that you use later on if you wish.
64+
values := []int{}
65+
66+
// And you can even add helpers that can be called only from inside your
67+
// puzzle solution.
68+
convert := func(s string) int {
69+
v, _ := strconv.Atoi(s)
70+
return v
71+
}
72+
73+
return Puzzle{
74+
// Init will be called before any of the solutions. Do all of your
75+
// expsensive pre-processing here.
76+
Init: func() {
77+
lines := strings.Split(data, "\n")
78+
for _, l := range lines {
79+
values = append(values, convert(l))
80+
}
81+
},
82+
// Parts contains all of the different sub-solutions that you need
83+
// to implement (looking at you Advent of Code).
84+
Parts: []Solution{
85+
// You can consume the pre-processed data in the solutions here
86+
func() int { return values[0] + 100 },
87+
func() int { return values[1] + 100 },
88+
func() int { return values[2] + 100 },
89+
},
90+
}
91+
}
92+
```
93+
94+
Once you've got the answers you need, I would recommend something like the following:
5495
```bash
5596
$ git add .
5697
$ git commit -m "Add solution to puzzle $(ls -l | grep puzzle | wc -l)"
@@ -64,6 +105,8 @@ Sometimes it's necessary to check that your code is doing what you expect withou
64105
$ make test
65106
```
66107

108+
Just beware, if you create your helper functions inside your generated puzzle function then they won't be accessible from your tests. To get around this, just create them outside of this function. And remember that `common.go` has been created for those helpers that you think might be used by several puzzles.
109+
67110
## Contributing to this template
68111

69112
To run the tests you will need to do the following:

0 commit comments

Comments
 (0)