1
0
Fork 0

Add aoc macro

This commit is contained in:
Case Duckworth 2020-12-03 23:52:04 +00:00
parent d29f9d8bc5
commit 7a58c7e612
1 changed files with 35 additions and 0 deletions

35
aoc.org
View File

@ -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 ^_^