Code organisation update

This commit is contained in:
Daniel Ziltener 2023-12-04 01:50:38 +01:00
parent 85fd8dd83c
commit 12e12e5ca5
Signed by: zilti
GPG Key ID: B38976E82C9DAE42
1 changed files with 35 additions and 28 deletions

View File

@ -1761,28 +1761,32 @@ in the engine schematic?*
#+end_src
#+NAME: day3-part1-calc
#+begin_src scheme :var input=day3-input :noweb yes
(import (chicken string))
<<day3-part1-records>>
<<day3-part1-indexing>>
<<day3-part1-number-char-p>>
<<day3-part1-finalize-token>>
<<day3-part1-compatible-with-buffer-p>>
<<day3-part1-tokenize-indexed-input>>
<<day3-part1-neighbours-p>>
<<day3-part1-real-part-number-p>>
<<day3-part1-fold>>
#+begin_src scheme
(let-values (((part-nums part-syms) (tokenize-indexed-input (index-input (string->list input)))))
(fold-part-numbers part-nums part-syms))
#+end_src
RESULTS: day3-part1-calc
#+NAME: day3-part1-calc-full
#+begin_src scheme :var input=day3-input :noweb yes :exports results
(import (chicken string))
<<day3-part1-records>>
<<day3-part1-indexing>>
<<day3-part1-number-char-p>>
<<day3-part1-finalize-token>>
<<day3-part1-compatible-with-buffer-p>>
<<day3-part1-tokenize-indexed-input>>
<<day3-part1-neighbours-p>>
<<day3-part1-real-part-number-p>>
<<day3-part1-fold>>
<<day3-part1-calc>>
#+end_src
RESULTS: day3-part1-calc-full
: 509115
#+begin_src scheme :tangle day3.scm
#+begin_src scheme :noweb yes :exports none :tangle day3.scm
(define (calc-part-1)
(let-values (((part-nums part-syms) (tokenize-indexed-input (index-input (string->list input)))))
(fold-part-numbers part-nums part-syms)))
<<day3-part1-calc>>)
#+end_src
** Part Two
@ -1863,8 +1867,15 @@ number.) Adding up all of the gear ratios produces *=467835=*.
0 gears))
#+end_src
#+NAME: day3-part2-calc
#+begin_src scheme
#+NAME: day3-part2-calc
#+begin_src scheme
(let-values (((part-nums part-syms) (tokenize-indexed-input (index-input (string->list input)))))
(let ((gear-candidates (map (lambda (x) (gather-neighbours x part-nums)) (filter-gear-candidates part-syms))))
(calc-gear-ratio gears)))
#+end_src
#+NAME: day3-part2-calc-full
#+begin_src scheme :var input=day3-input :noweb yes :exports results
(import (chicken string))
<<day3-part1-records>>
<<day3-part1-indexing>>
@ -1876,25 +1887,21 @@ number.) Adding up all of the gear ratios produces *=467835=*.
<<day3-part2-sym-neighbour-count>>
<<day3-part2-filter>>
<<day3-part2-fold>>
(let-values (((part-nums part-syms) (tokenize-indexed-input (index-input (string->list input)))))
(let ((gear-candidates (map (lambda (x) (gather-neighbours x part-nums)) (filter-gear-candidates part-syms))))
(calc-gear-ratio gears)))
<<day3-part2-calc>>
#+end_src
#+RESULTS: day3-part2-calc
#+RESULTS: day3-part2-calc-full
: 75220503
#+begin_src scheme :tangle day3.scm
(define (calc-part-2)
(let-values (((part-nums part-syms) (tokenize-indexed-input (index-input (string->list input)))))
(let ((gear-candidates (map (lambda (x) (gather-neighbours x part-nums)) (filter-gear-candidates part-syms))))
(calc-gear-ratio gear-candidates))))
#+begin_src scheme :noweb yes :exports none :tangle day3.scm
(define (calc-part-2)
<<day3-part2-calc>>)
#+end_src
** Puzzle Input
#+NAME: day3-input
#+begin_example
#+begin_src fundamental
.....664...998........343...............851............................2............414.....................3....................948.164....
......*..................*617....885...*....................-......250.........536..........470...#..................../4......=.....*......
...407...570..218................-.....654........776.....920.........*753...........566......*..347.....61.-979..786........935...42.......
@ -2035,4 +2042,4 @@ number.) Adding up all of the gear ratios produces *=467835=*.
......87...318......472...........%449.....=............720.........%.................257...29...........*.........-.....656................
..666........*....*.....920.....................................................&......*........................759..........875$...........
......138....366..797...........584.......247.........................427..206..843...618.....530......................................172..
#+end_example
#+end_src