diff --git a/aoc.asd b/aoc.asd index 714f853..af3fe08 100644 --- a/aoc.asd +++ b/aoc.asd @@ -10,10 +10,12 @@ :source-control "https://forge.snamellit.com/pti/aoc-cl" :depends-on (#:dexador #:plump - #:lquery) + #:lquery + #:fiveam) :components ((:module "src" :components - ((:file "main")))) + ((:file "main") + (:file "2018/day06")))) :description "Advent of Code challenges and solutions." :long-description "Solutions for the AOC challenges." :in-order-to ((test-op (test-op "aoc/tests")))) diff --git a/src/2018/day06.lisp b/src/2018/day06.lisp new file mode 100644 index 0000000..3993dd8 --- /dev/null +++ b/src/2018/day06.lisp @@ -0,0 +1,44 @@ +(defpackage :aoc/2018/06 + (:use :cl :aoc :fiveam)) + +(in-package :aoc/2018/06) + +(defvar test-data (test-input 2018 6)) + + +(defstruct point-2d + (x 0 :type fixnum) + (y 0 :type fixnum)) + +(defvar sample-data '((1 1) + (1 6) + (8 3) + (3 4) + (5 5) + (8 9))) + +(defun make-points (data) + (map 'list (lambda (p) (make-point-2d :x (first p) :y (second p))) data)) + +(defvar sample-points (make-points sample-data)) + +(defun top-left (points) + (let ((x-min (apply #'min (map 'list #'point-2d-x points) )) + (y-min (apply #'min (map 'list #'point-2d-y points) ))) + (make-point-2d :x x-min :y y-min))) + +(defun bottom-right (points) + (let ((x-max (apply #'max (map 'list #'point-2d-x points) )) + (y-max (apply #'max (map 'list #'point-2d-y points) ))) + (make-point-2d :x x-max :y y-max))) + +(def-suite 2018-day-6) +(in-suite 2018-day-6) + +(test find-top-left + (let ((result (top-left sample-points))) + (is (equalp (make-point-2d :x 1 :y 1) result)))) + +(test find-bottom-right + (let ((result (bottom-right sample-points))) + (is (equalp (make-point-2d :x 8 :y 9) result)))) diff --git a/src/main.lisp b/src/main.lisp index 63a91b1..5817dbd 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -1,5 +1,8 @@ (defpackage aoc - (:use :cl)) + (:use :cl) + (:export + #:test-input)) + (in-package :aoc) (defun load-ql-dependencies ()