diff --git a/README.md b/README.md index f05fda0..697f8ac 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ _in which I attempt to use a different language every day_ 3. PostScript 4. Uiua 5. JVM bytecode -6. ?? +6. LaTeX 7. ?? 8. ?? 9. ?? diff --git a/d06/.gitignore b/d06/.gitignore new file mode 100644 index 0000000..20e2753 --- /dev/null +++ b/d06/.gitignore @@ -0,0 +1,5 @@ +*.log +*.aux +*.xdv +*.dvi +*.pdf \ No newline at end of file diff --git a/d06/README.md b/d06/README.md index 37cae30..c0dee84 100644 --- a/d06/README.md +++ b/d06/README.md @@ -1,11 +1,16 @@ # Day 6 -| | | -|-------------------|-------------------| -| Language | ?? | -| Input Method | ?? | -| Output Method | ?? | +| | | +|-------------------|-----------------------| +| Language | TeX (LaTeX) | +| Input Method | File (hardcoded path) | +| Output Method | PDF document | ## Running +Place your input file in `inputs/real/day6.txt` relative to the root of the repository. -## Notes \ No newline at end of file +Then compile `day6.tex` using your favourite TeX engine - I use `tectonic`, but the standard +`pdflatex`/`xelatex`/`lualatex` should all work fine too. + +## Notes +Dealing with the spaces in the input for part 2 required some proper TeX category code shenanigans™ \ No newline at end of file diff --git a/d06/day6.tex b/d06/day6.tex new file mode 100644 index 0000000..d4277c7 --- /dev/null +++ b/d06/day6.tex @@ -0,0 +1,84 @@ +\documentclass{minimal} +\setlength\parindent{0pt} +\setlength\parskip{\baselineskip} +\begin{document} +\ExplSyntaxOn + \seq_new:N \l__aoc_problems_seq + \ior_new:N \l__aoc_input_ior + \ior_open:Nn \l__aoc_input_ior {../inputs/real/day6.txt} + \ior_str_map_inline:Nn \l__aoc_input_ior { + \seq_set_split:Nnn \l_tmpa_seq {~} {#1} + \seq_remove_all:Nn \l_tmpa_seq {} + \seq_if_empty:NTF \l__aoc_problems_seq { + \seq_map_inline:Nn \l_tmpa_seq { + \seq_put_right:Nn \l__aoc_problems_seq {##1} + } + } { + \seq_clear:N \l_tmpb_seq + \seq_map_indexed_inline:Nn \l_tmpa_seq { + \seq_put_right:Ne \l_tmpb_seq {\seq_item:Nn \l__aoc_problems_seq {##1}~##2} + } + \seq_set_eq:NN \l__aoc_problems_seq \l_tmpb_seq + } + } + \ior_close:N \l__aoc_input_ior + + \fp_new:N \l__aoc_partone_answer_fp + \seq_map_inline:Nn \l__aoc_problems_seq { + \seq_set_split:Nnn \l_tmpa_seq {~} {#1} + \tl_clear:N \l_tmpa_tl + \seq_pop_right:NN \l_tmpa_seq \l_tmpa_tl + \seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl + \fp_set:NV \l_tmpa_fp \l_tmpb_tl + \seq_map_inline:Nn \l_tmpa_seq { + \fp_set:Nn \l_tmpa_fp {\l_tmpa_fp \l_tmpa_tl ##1} + } + \fp_add:Nn \l__aoc_partone_answer_fp {\l_tmpa_fp} + } + Part~1:~\fp_use:N \l__aoc_partone_answer_fp\\ + + \ior_open:Nn \l__aoc_input_ior {../inputs/real/day6.txt} + \seq_new:N \l__aoc_operators_seq + \seq_new:N \l__aoc_rows_seq + \ior_str_map_inline:Nn \l__aoc_input_ior { + \tl_if_in:nnTF {#1} {*} { + \seq_set_split:Nnn \l__aoc_operators_seq {~} {#1} + \seq_remove_all:Nn \l__aoc_operators_seq {} + } { + \tl_set_rescan:Nnn \l_tmpa_tl {\char_set_catcode:nn {32} {12}} {#1} + \seq_put_right:NV \l__aoc_rows_seq \l_tmpa_tl + } + } + \ior_close:N \l__aoc_input_ior + + \int_new:N \l__aoc_max_row_length_int + \seq_map_inline:Nn \l__aoc_rows_seq { + \int_set:Nn \l__aoc_max_row_length_int {\int_max:nn {\l__aoc_max_row_length_int} {\tl_count_tokens:n {#1}}} + } + + \fp_new:N \l__aoc_parttwo_answer_fp + \int_new:N \l__aoc_column_int + \seq_new:N \l__aoc_current_calculation_seq + \int_until_do:nNnn {\l__aoc_column_int} > {\l__aoc_max_row_length_int} { + \int_incr:N \l__aoc_column_int + \tl_clear:N \l_tmpa_tl + \seq_map_variable:NNn \l__aoc_rows_seq \l_tmpb_tl { + \tl_put_right:Ne \l_tmpa_tl {\tl_item:Nn \l_tmpb_tl {\l__aoc_column_int}} + } + \tl_set_rescan:NnV \l_tmpa_tl {} \l_tmpa_tl + \tl_if_empty:NTF \l_tmpa_tl { + \seq_pop_left:NN \l__aoc_current_calculation_seq \l_tmpa_tl + \fp_set:NV \l_tmpa_fp \l_tmpa_tl + \seq_pop_left:NN \l__aoc_operators_seq \l_tmpb_tl + \seq_map_inline:Nn \l__aoc_current_calculation_seq { + \fp_set:Nn \l_tmpa_fp {\l_tmpa_fp \l_tmpb_tl #1} + } + \fp_add:Nn \l__aoc_parttwo_answer_fp {\l_tmpa_fp} + \seq_clear:N \l__aoc_current_calculation_seq + } { + \seq_put_right:NV \l__aoc_current_calculation_seq \l_tmpa_tl + } + } + Part~2:~\fp_use:N \l__aoc_parttwo_answer_fp +\ExplSyntaxOff +\end{document} \ No newline at end of file