From 3ef62a9d5cf95c218e80455021e69d3bf5bf1541 Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Tue, 24 Nov 2020 01:23:11 -0500 Subject: [PATCH] Add project structure and Day 00 code (2019/Day 01) --- adventofcode2020.asd | 23 +++++++++ package.lisp | 7 +++ res/day00 | 100 ++++++++++++++++++++++++++++++++++++++ src/adventofcode2020.lisp | 13 +++++ src/day00.lisp | 30 ++++++++++++ src/utilities.lisp | 9 ++++ t/adventofcode2020.lisp | 3 ++ t/day00.lisp | 2 + 8 files changed, 187 insertions(+) create mode 100644 adventofcode2020.asd create mode 100644 package.lisp create mode 100644 res/day00 create mode 100644 src/adventofcode2020.lisp create mode 100644 src/day00.lisp create mode 100644 src/utilities.lisp create mode 100644 t/adventofcode2020.lisp create mode 100644 t/day00.lisp diff --git a/adventofcode2020.asd b/adventofcode2020.asd new file mode 100644 index 0000000..96f4fbd --- /dev/null +++ b/adventofcode2020.asd @@ -0,0 +1,23 @@ +;;;; adventofcode2020.asd + +(asdf:defsystem #:adventofcode2020 + :description "Advent of Code 2020" + :author "Jack Kinsey " + :version "0.0.1" + :serial t + :depends-on (:alexandria + :arrow-macros + :fiveam) + :pathname "src/" + :components ((:file "package") + (:file "adventofcode2020")) + :in-order-to ((test-op (test-op :adventofcode2020/test)))) + +(asdf:defsystem #:adventofcode2020/tests + :description "Advent of Code 2020 test suite" + :author "Jack Kinsey " + :depends-on (:adventofcode2020 :fiveam) + :pathname "t/" + :components ((:file "package") + (:file "adventofcode2020")) + :perform (test-op (o c) (symbol-call :5am :run! :adventofcode2020))) diff --git a/package.lisp b/package.lisp new file mode 100644 index 0000000..363adb0 --- /dev/null +++ b/package.lisp @@ -0,0 +1,7 @@ +(defpackage #:adventofcode2020 + (:use #:cl + #:arrow-macros + #:alexandria + #:fiveam) + (:import-from :cl-ppcre :split) + (:nicknames :aoc2020)) diff --git a/res/day00 b/res/day00 new file mode 100644 index 0000000..eea337c --- /dev/null +++ b/res/day00 @@ -0,0 +1,100 @@ +95065 +129298 +145573 +95743 +59139 +78323 +124445 +69015 +81990 +83254 +139274 +92101 +74245 +104038 +61955 +80642 +110376 +89992 +84392 +117830 +140144 +80076 +111285 +107135 +98741 +103753 +141922 +130503 +60409 +73891 +84781 +118319 +93610 +143228 +99616 +65353 +102388 +123813 +88335 +95459 +133635 +108771 +101999 +73850 +106490 +53396 +110330 +140258 +73958 +60273 +101401 +128995 +61495 +114674 +71955 +107049 +79374 +52359 +107925 +91789 +69174 +133966 +85063 +62856 +96965 +97100 +81638 +104488 +131368 +59015 +149357 +65193 +61489 +126089 +141224 +100596 +93144 +109421 +121988 +135890 +70141 +53531 +59900 +98981 +66796 +113700 +109535 +100721 +87240 +99883 +81637 +80064 +143154 +75778 +64835 +59235 +103907 +121637 +118525 +125730 diff --git a/src/adventofcode2020.lisp b/src/adventofcode2020.lisp new file mode 100644 index 0000000..54a6aca --- /dev/null +++ b/src/adventofcode2020.lisp @@ -0,0 +1,13 @@ +(in-package #:adventofcode2020) + +(defmacro day (num var &body body) + (let ((day-str (format nil "day~2,'0D" num))) + `(let ((,var (alexandria:read-file-into-string ,(format nil "./res/~A" day-str)))) + ,@body))) + +(defun part1 (str) + (format t "Part 1: ~A~%" str)) + +(defun part2 (str) + (format t "Part 2: ~A~%" str)) + diff --git a/src/day00.lisp b/src/day00.lisp new file mode 100644 index 0000000..a6e755c --- /dev/null +++ b/src/day00.lisp @@ -0,0 +1,30 @@ +(in-package #:adventofcode2020) + +(defun simple-fuel (mass) + (- (floor (/ mass 3)) + 2)) + +(defun complex-fuel (mass) + (loop with m = (simple-fuel mass) + while (> m 0) sum m + do (setf m (simple-fuel m)))) + +(day 00 input + (let ((modules (int-list-from input))) + (part1 (reduce #'+ (mapcar #'simple-fuel modules))) + (part2 (reduce #'+ (mapcar #'complex-fuel modules))))) + +(def-suite day00) +(in-suite day00) + +(test simple-fuel + (is (equal + '(2 2 654 33583) + (mapcar #'simple-fuel '(12 14 1969 100756))))) + +(test complex-fuel + (is (equal + '(2 966 50346) + (mapcar #'complex-fuel '(14 1969 100756))))) + +(run! 'day00) diff --git a/src/utilities.lisp b/src/utilities.lisp new file mode 100644 index 0000000..c677e96 --- /dev/null +++ b/src/utilities.lisp @@ -0,0 +1,9 @@ +(in-package #:adventofcode2020) + +;;; Utility functions + +(defun list-from (str) + (split "\\n" str)) + +(defun int-list-from (str) + (mapcar #'parse-integer (split "\\n" str))) diff --git a/t/adventofcode2020.lisp b/t/adventofcode2020.lisp new file mode 100644 index 0000000..9078932 --- /dev/null +++ b/t/adventofcode2020.lisp @@ -0,0 +1,3 @@ +;;;; adventofcode2020.lisp + +(in-package #:adventofcode2020) diff --git a/t/day00.lisp b/t/day00.lisp new file mode 100644 index 0000000..b090757 --- /dev/null +++ b/t/day00.lisp @@ -0,0 +1,2 @@ +(in-package #:adventofcode2020) + -- 2.38.5