77
88# Script to generate a skeletal Advent of Code solution in Julia.
99
10+ using UUIDs
11+
1012function generate_into (daydir)
1113 m = match (r" (\d +)$" , daydir)
1214 if isnothing (m)
@@ -26,23 +28,26 @@ function generate_into(daydir)
2628 # Use of this source code is governed by an MIT-style
2729 # license that can be found in the LICENSE file or at
2830 # https://opensource.org/licenses/MIT.
29- #
30- # https://adventofcode.com/2023/day/$daynum
3131
32+ \" ""# Advent of Code 2023 day $daynum
33+ [Read the puzzle](https://adventofcode.com/2023/day/$daynum )
34+ \" ""
3235 module Day$daynum
3336
3437 function part1(lines)
35- input = map(lines) do line
36- line
37- end
38+ input = parseinput(lines)
3839 :TODO
3940 end
4041
4142 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
4349 line
4450 end
45- :TODO
4651 end
4752
4853 include("../Runner.jl")
@@ -52,8 +57,95 @@ function generate_into(daydir)
5257 write (jlfile, code)
5358 chmod (jlfile, 0o755 )
5459 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+
55147 mkinput (base, " example" )
56- inputdir = joinpath (dirname ( PROGRAM_FILE ) , " input" , daynum)
148+ inputdir = joinpath (@__DIR__ , " input" , daynum)
57149 mkpath (inputdir)
58150 mkinput (inputdir, " actual" )
59151 for name in readdir (inputdir)
0 commit comments