Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit b126da2

Browse files
committed
Add scaffold for all 25 solutions
1 parent 7816529 commit b126da2

File tree

31 files changed

+486
-32
lines changed

31 files changed

+486
-32
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.23-alpine
2+
WORKDIR /app
3+
COPY go.mod .
4+
COPY common common
5+
6+
ARG DAY
7+
COPY solutions/day${DAY} solutions/day${DAY}
8+
RUN go build -o app solutions/day${DAY}/main.go
9+
EXPOSE 3000
10+
CMD ["./app"]

common/setup.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ func Setup(
1515
part1 Solution,
1616
part2 Solution,
1717
) {
18-
http.HandleFunc("/1", createHandler(part1))
19-
http.HandleFunc("/2", createHandler(part2))
18+
http.HandleFunc("/1", createHandler(day, 1, part1))
19+
http.HandleFunc("/2", createHandler(day, 2, part2))
2020
fmt.Printf("Starting Day #%d service on port 3000\n", day)
2121
if err := http.ListenAndServe(":3000", nil); err != nil {
2222
log.Fatal(err)
2323
}
2424
}
2525

26-
func createHandler(solution func(string) string) func(http.ResponseWriter, *http.Request) {
26+
func createHandler(
27+
day int,
28+
part int,
29+
solution func(string) string,
30+
) func(http.ResponseWriter, *http.Request) {
31+
if solution == nil {
32+
solution = defaultHandler(day, part)
33+
}
34+
2735
return func(w http.ResponseWriter, r *http.Request) {
2836
if err := methodMustBePost(w, r); err != nil {
2937
fmt.Print(err.Error())
@@ -45,6 +53,15 @@ func createHandler(solution func(string) string) func(http.ResponseWriter, *http
4553
}
4654
}
4755

56+
func defaultHandler(
57+
day int,
58+
part int,
59+
) Solution {
60+
return func(input string) string {
61+
return fmt.Sprintf("Solution for day %d part %d not implemented yet", day, part)
62+
}
63+
}
64+
4865
func methodMustBePost(w http.ResponseWriter, r *http.Request) error {
4966
if r.Method != http.MethodPost {
5067
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed)

day01/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

day02/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

day03/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker-compose.yml

Lines changed: 256 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,274 @@ services:
22
day01:
33
build:
44
context: .
5-
dockerfile: day01/Dockerfile
5+
dockerfile: Dockerfile
6+
args: { DAY: '01' }
67
ports: [ "3001:3000" ]
78
develop:
89
watch:
9-
- action: rebuild
10-
path: ./day01/
10+
- { action: rebuild, path: solutions/day01/ }
11+
- { action: rebuild, path: common/ }
12+
1113
day02:
1214
build:
1315
context: .
14-
dockerfile: day02/Dockerfile
16+
dockerfile: Dockerfile
17+
args: { DAY: '02' }
1518
ports: [ "3002:3000" ]
1619
develop:
1720
watch:
18-
- action: rebuild
19-
path: ./day02/
21+
- { action: rebuild, path: solutions/day01/ }
22+
- { action: rebuild, path: common/ }
23+
2024
day03:
2125
build:
2226
context: .
23-
dockerfile: day03/Dockerfile
27+
dockerfile: Dockerfile
28+
args: { DAY: '03' }
2429
ports: [ "3003:3000" ]
2530
develop:
2631
watch:
27-
- action: rebuild
28-
path: ./day03/
32+
- { action: rebuild, path: solutions/day03/ }
33+
- { action: rebuild, path: common/ }
34+
35+
day04:
36+
build:
37+
context: .
38+
dockerfile: Dockerfile
39+
args: { DAY: '04' }
40+
ports: [ "3004:3000" ]
41+
develop:
42+
watch:
43+
- { action: rebuild, path: solutions/day04/ }
44+
- { action: rebuild, path: common/ }
45+
46+
day05:
47+
build:
48+
context: .
49+
dockerfile: Dockerfile
50+
args: { DAY: '05' }
51+
ports: [ "3005:3000" ]
52+
develop:
53+
watch:
54+
- { action: rebuild, path: solutions/day05/ }
55+
- { action: rebuild, path: common/ }
56+
57+
day06:
58+
build:
59+
context: .
60+
dockerfile: Dockerfile
61+
args: { DAY: '06' }
62+
ports: [ "3006:3000" ]
63+
develop:
64+
watch:
65+
- { action: rebuild, path: solutions/day06/ }
66+
- { action: rebuild, path: common/ }
67+
68+
day07:
69+
build:
70+
context: .
71+
dockerfile: Dockerfile
72+
args: { DAY: '07' }
73+
ports: [ "3007:3000" ]
74+
develop:
75+
watch:
76+
- { action: rebuild, path: solutions/day07/ }
77+
- { action: rebuild, path: common/ }
78+
79+
day08:
80+
build:
81+
context: .
82+
dockerfile: Dockerfile
83+
args: { DAY: '08' }
84+
ports: [ "3008:3000" ]
85+
develop:
86+
watch:
87+
- { action: rebuild, path: solutions/day08/ }
88+
- { action: rebuild, path: common/ }
89+
90+
day09:
91+
build:
92+
context: .
93+
dockerfile: Dockerfile
94+
args: { DAY: '09' }
95+
ports: [ "3009:3000" ]
96+
develop:
97+
watch:
98+
- { action: rebuild, path: solutions/day09/ }
99+
- { action: rebuild, path: common/ }
100+
101+
day10:
102+
build:
103+
context: .
104+
dockerfile: Dockerfile
105+
args: { DAY: '10' }
106+
ports: [ "3010:3000" ]
107+
develop:
108+
watch:
109+
- { action: rebuild, path: solutions/day10/ }
110+
- { action: rebuild, path: common/ }
111+
112+
day11:
113+
build:
114+
context: .
115+
dockerfile: Dockerfile
116+
args: { DAY: '11' }
117+
ports: [ "3011:3000" ]
118+
develop:
119+
watch:
120+
- { action: rebuild, path: solutions/day11/ }
121+
- { action: rebuild, path: common/ }
122+
123+
day12:
124+
build:
125+
context: .
126+
dockerfile: Dockerfile
127+
args: { DAY: '12' }
128+
ports: [ "3012:3000" ]
129+
develop:
130+
watch:
131+
- { action: rebuild, path: solutions/day12/ }
132+
- { action: rebuild, path: common/ }
133+
134+
day13:
135+
build:
136+
context: .
137+
dockerfile: Dockerfile
138+
args: { DAY: '13' }
139+
ports: [ "3013:3000" ]
140+
develop:
141+
watch:
142+
- { action: rebuild, path: solutions/day13/ }
143+
- { action: rebuild, path: common/ }
144+
145+
day14:
146+
build:
147+
context: .
148+
dockerfile: Dockerfile
149+
args: { DAY: '14' }
150+
ports: [ "3014:3000" ]
151+
develop:
152+
watch:
153+
- { action: rebuild, path: solutions/day14/ }
154+
- { action: rebuild, path: common/ }
155+
156+
day15:
157+
build:
158+
context: .
159+
dockerfile: Dockerfile
160+
args: { DAY: '15' }
161+
ports: [ "3015:3000" ]
162+
develop:
163+
watch:
164+
- { action: rebuild, path: solutions/day15/ }
165+
- { action: rebuild, path: common/ }
166+
167+
day16:
168+
build:
169+
context: .
170+
dockerfile: Dockerfile
171+
args: { DAY: '16' }
172+
ports: [ "3016:3000" ]
173+
develop:
174+
watch:
175+
- { action: rebuild, path: solutions/day16/ }
176+
- { action: rebuild, path: common/ }
177+
178+
day17:
179+
build:
180+
context: .
181+
dockerfile: Dockerfile
182+
args: { DAY: '17' }
183+
ports: [ "3017:3000" ]
184+
develop:
185+
watch:
186+
- { action: rebuild, path: solutions/day17/ }
187+
- { action: rebuild, path: common/ }
188+
189+
day18:
190+
build:
191+
context: .
192+
dockerfile: Dockerfile
193+
args: { DAY: '18' }
194+
ports: [ "3018:3000" ]
195+
develop:
196+
watch:
197+
- { action: rebuild, path: solutions/day18/ }
198+
- { action: rebuild, path: common/ }
199+
200+
day19:
201+
build:
202+
context: .
203+
dockerfile: Dockerfile
204+
args: { DAY: '19' }
205+
ports: [ "3019:3000" ]
206+
develop:
207+
watch:
208+
- { action: rebuild, path: solutions/day19/ }
209+
- { action: rebuild, path: common/ }
210+
211+
day20:
212+
build:
213+
context: .
214+
dockerfile: Dockerfile
215+
args: { DAY: '20' }
216+
ports: [ "3020:3000" ]
217+
develop:
218+
watch:
219+
- { action: rebuild, path: solutions/day20/ }
220+
- { action: rebuild, path: common/ }
221+
222+
day21:
223+
build:
224+
context: .
225+
dockerfile: Dockerfile
226+
args: { DAY: '21' }
227+
ports: [ "3021:3000" ]
228+
develop:
229+
watch:
230+
- { action: rebuild, path: solutions/day21/ }
231+
- { action: rebuild, path: common/ }
232+
233+
day22:
234+
build:
235+
context: .
236+
dockerfile: Dockerfile
237+
args: { DAY: '22' }
238+
ports: [ "3022:3000" ]
239+
develop:
240+
watch:
241+
- { action: rebuild, path: solutions/day22/ }
242+
- { action: rebuild, path: common/ }
243+
244+
day23:
245+
build:
246+
context: .
247+
dockerfile: Dockerfile
248+
args: { DAY: '23' }
249+
ports: [ "3023:3000" ]
250+
develop:
251+
watch:
252+
- { action: rebuild, path: solutions/day23/ }
253+
- { action: rebuild, path: common/ }
254+
255+
day24:
256+
build:
257+
context: .
258+
dockerfile: Dockerfile
259+
args: { DAY: '24' }
260+
ports: [ "3024:3000" ]
261+
develop:
262+
watch:
263+
- { action: rebuild, path: solutions/day24/ }
264+
- { action: rebuild, path: common/ }
265+
266+
day25:
267+
build:
268+
context: .
269+
dockerfile: Dockerfile
270+
args: { DAY: '25' }
271+
ports: [ "3025:3000" ]
272+
develop:
273+
watch:
274+
- { action: rebuild, path: solutions/day25/ }
275+
- { action: rebuild, path: common/ }

day01/main.go renamed to solutions/day01/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func part1(input string) string {
6060
sum += diff
6161
}
6262

63-
return fmt.Sprintf("Result for part 1: %d\n", sum)
63+
return fmt.Sprintf("Result for part 1: %d", sum)
6464
}
6565

6666
func part2(input string) string {
@@ -79,5 +79,5 @@ func part2(input string) string {
7979
sum += l * rightMap[l]
8080
}
8181

82-
return fmt.Sprintf("Result for part 2: %d\n", sum)
82+
return fmt.Sprintf("Result for part 2: %d", sum)
8383
}
File renamed without changes.
File renamed without changes.

solutions/day04/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"github.com/terminalnode/adventofcode2024/common"
5+
)
6+
7+
func main() {
8+
common.Setup(4, nil, nil)
9+
}

0 commit comments

Comments
 (0)