7
7
8
8
# Script to generate a skeletal Advent of Code solution in Julia.
9
9
10
+ using UUIDs
11
+
10
12
function generate_into (daydir)
11
13
m = match (r" (\d +)$" , daydir)
12
14
if isnothing (m)
@@ -26,23 +28,26 @@ function generate_into(daydir)
26
28
# Use of this source code is governed by an MIT-style
27
29
# license that can be found in the LICENSE file or at
28
30
# https://opensource.org/licenses/MIT.
29
- #
30
- # https://adventofcode.com/2023/day/$daynum
31
31
32
+ \" ""# Advent of Code 2023 day $daynum
33
+ [Read the puzzle](https://adventofcode.com/2023/day/$daynum )
34
+ \" ""
32
35
module Day$daynum
33
36
34
37
function part1(lines)
35
- input = map(lines) do line
36
- line
37
- end
38
+ input = parseinput(lines)
38
39
:TODO
39
40
end
40
41
41
42
function part2(lines)
42
- input = map(lines) do line
43
+ input = parseinput(lines)
44
+ :TODO
45
+ end
46
+
47
+ function parseinput(lines)
48
+ map(lines) do line
43
49
line
44
50
end
45
- :TODO
46
51
end
47
52
48
53
include("../Runner.jl")
@@ -52,8 +57,95 @@ function generate_into(daydir)
52
57
write (jlfile, code)
53
58
chmod (jlfile, 0o755 )
54
59
end
60
+
61
+ notebook = joinpath (base, " notebook.jl" )
62
+ if ! isfile (notebook)
63
+ header_uuid = UUIDs. uuid4 ()
64
+ preamble_uuid = UUIDs. uuid4 ()
65
+ inputstats_uuid = UUIDs. uuid4 ()
66
+ functions_uuid = UUIDs. uuid4 ()
67
+ vars_uuid = UUIDs. uuid4 ()
68
+ resultshead_uuid = UUIDs. uuid4 ()
69
+ results_uuid = UUIDs. uuid4 ()
70
+ code = """
71
+ ### A Pluto.jl notebook ###
72
+ # v0.19.32
73
+ #
74
+ # Copyright 2023 Google LLC
75
+ #
76
+ # Use of this source code is governed by an MIT-style
77
+ # license that can be found in the LICENSE file or at
78
+ # https://opensource.org/licenses/MIT.
79
+
80
+ using Markdown
81
+ using InteractiveUtils
82
+
83
+ # ╔═╡ $header_uuid
84
+ @doc Day$daynum
85
+
86
+ # ╔═╡ $preamble_uuid
87
+ begin
88
+ import Pkg
89
+ Pkg.activate()
90
+ try
91
+ @eval using Revise
92
+ catch e
93
+ @warn "Need to install Revise?" exception=(e)
94
+ end
95
+ using Day$daynum
96
+ using Runner
97
+ inputexample = "input.example.txt"
98
+ inputactual = "input.actual.txt"
99
+ run() = Runner.run_module(Day$daynum , Runner.inputfiles(); verbose=true)
100
+ println("Day$daynum ready, just run() or Day$daynum .part1(readlines(inputexample))")
101
+ end
102
+
103
+ # ╔═╡ $inputstats_uuid
104
+ Runner.inputstats();
105
+
106
+ # ╔═╡ $functions_uuid
107
+ begin
108
+ function parseinput(lines)
109
+ Day$daynum .parseinput(lines)
110
+ #map(lines) do line
111
+ #parse(Int, line)
112
+ #if (m = match(r"^(\\ S+) (\\ S+)\$ ", line)) !== nothing
113
+ # (foo, bar) = m.captures
114
+ #end
115
+ #end
116
+ end
117
+ end;
118
+
119
+ # ╔═╡ $vars_uuid
120
+ begin # Useful variables
121
+ exampleexpected = Runner.expectedfor(inputexample)
122
+ examplelines = readlines(inputexample)
123
+ input = parseinput(examplelines)
124
+ end
125
+
126
+ # ╔═╡ $resultshead_uuid
127
+ md"## Results"
128
+
129
+ # ╔═╡ $results_uuid
130
+ Runner.run_module(Day$daynum , [
131
+ inputexample,
132
+ inputactual,
133
+ ], verbose=true)
134
+
135
+ # ╔═╡ Cell order:
136
+ # ╟─$header_uuid
137
+ # ╟─$preamble_uuid
138
+ # ╠═$inputstats_uuid
139
+ # ╠═$functions_uuid
140
+ # ╠═$vars_uuid
141
+ # ╟─$resultshead_uuid
142
+ # ╠═$results_uuid
143
+ """
144
+ write (notebook, code)
145
+ end
146
+
55
147
mkinput (base, " example" )
56
- inputdir = joinpath (dirname ( PROGRAM_FILE ) , " input" , daynum)
148
+ inputdir = joinpath (@__DIR__ , " input" , daynum)
57
149
mkpath (inputdir)
58
150
mkinput (inputdir, " actual" )
59
151
for name in readdir (inputdir)
0 commit comments