Add aoc macro
This commit is contained in:
parent
d29f9d8bc5
commit
7a58c7e612
35
aoc.org
35
aoc.org
|
@ -4590,3 +4590,38 @@ NOW we can multiply everything:
|
|||
: 3898725600
|
||||
|
||||
AND THAT IS CORRECT 😎
|
||||
|
||||
* Interlude: A Macro
|
||||
|
||||
I need to write a macro to reduce boilerplate
|
||||
|
||||
#+NAME: aoc
|
||||
#+begin_src emacs-lisp
|
||||
(defmacro aoc (input &rest body)
|
||||
"Reduce boilerplate for AoC challenges."
|
||||
`(let ((lines (split-string ,input "\n+")))
|
||||
,@body))
|
||||
#+end_src
|
||||
|
||||
** testing it
|
||||
:PROPERTIES:
|
||||
:header-args: :noweb yes
|
||||
:END:
|
||||
|
||||
#+begin_src emacs-lisp :var input=input-1a
|
||||
<<aoc>>
|
||||
(aoc input
|
||||
(let ((list (seq-map #'string-to-number lines))
|
||||
(result 0))
|
||||
(catch 'return
|
||||
(while list
|
||||
(setq n (pop list))
|
||||
(dolist (m list result)
|
||||
(when (= (+ n m) 2020)
|
||||
(throw 'return (* n m))))))))
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 969024
|
||||
|
||||
Cool, it works ^_^
|
||||
|
|
Loading…
Reference in New Issue