Skip to content

Instantly share code, notes, and snippets.

@laat
Created December 1, 2020 23:03
Show Gist options
  • Save laat/d96c7ad84227ecf5c56f26bf389fbc5c to your computer and use it in GitHub Desktop.
Save laat/d96c7ad84227ecf5c56f26bf389fbc5c to your computer and use it in GitHub Desktop.
org-mode and elisp

Advent Of Code 2020

Using org-mode and Emacs Lisp to solve Advent of Code.

(org-babel-lob-ingest "./library-of-babel.org")

Day 1

Part 1

Read the CSV

"1-1.txt"
(require 'cl-lib)

(defun laat/aoc-1-1 (xs)
  (apply '* (cl-intersection (mapcar (lambda (arg) (- 2020 arg)) xs) xs)))

(laat/aoc-1-1 (mapcar 'string-to-number (mapcar 'car example)))

Part 2

Read the CSV, it’s the same as 1-1.

"1-1.txt"
(require 'cl-lib)

(defun laat/aoc-1-2 (xs)
  (apply '* (car
             (cl-remove-if
              (lambda (x) (not (equal (apply '+ x) 2020)))
              (mapcan
               (lambda (a)
                 (mapcan
                  (lambda (b)
                    (mapcar
                     (lambda (c) (list a b c)) xs)) xs)) xs)))))

(laat/aoc-1-2 (mapcar 'string-to-number (mapcar 'car example)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment