--- a/advent.asd Fri Nov 29 15:15:05 2019 -0500
+++ b/advent.asd Sun Dec 01 11:39:22 2019 -0500
@@ -42,4 +42,5 @@
(:module "src" :serial t
:components ((:file "utils")
(:file "number-spiral")
- (:auto-module "2018")))))
+ (:auto-module "2018")
+ (:auto-module "2019")))))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data/2019/01.txt Sun Dec 01 11:39:22 2019 -0500
@@ -0,0 +1,100 @@
+63455
+147371
+83071
+57460
+74392
+145303
+130181
+53102
+120073
+93111
+144471
+105327
+116466
+67222
+122845
+146097
+92014
+114428
+96796
+131140
+101481
+87953
+101415
+75739
+64263
+94257
+140426
+62387
+84464
+104547
+103581
+89121
+123301
+64993
+143555
+55246
+120986
+67596
+146173
+149707
+60285
+83517
+73782
+103464
+140506
+78400
+140672
+141638
+84470
+116879
+100701
+63976
+135748
+65021
+120086
+147249
+55441
+135315
+147426
+93676
+91384
+110918
+123368
+102430
+144807
+82761
+134357
+62990
+85171
+134886
+69166
+119744
+80648
+96752
+89379
+136178
+95175
+124306
+51990
+57564
+111347
+79317
+95357
+85765
+137827
+105014
+110742
+105014
+149330
+78437
+107908
+139044
+143304
+90614
+52119
+147113
+119815
+125634
+104335
+138295
--- a/package.lisp Fri Nov 29 15:15:05 2019 -0500
+++ b/package.lisp Sun Dec 01 11:39:22 2019 -0500
@@ -2,6 +2,7 @@
(:use :cl :losh :iterate :advent.quickutils)
(:export
:define-problem
+ :define-problem-tests
:read-all
:read-lines
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/2019/day-01.lisp Sun Dec 01 11:39:22 2019 -0500
@@ -0,0 +1,18 @@
+(defpackage :advent/2019/01 #.cl-user::*advent-use*)
+(in-package :advent/2019/01)
+
+
+(defun fuel-required (module-mass)
+ (max 0 (- (floor module-mass 3) 2)))
+
+(defun complete-fuel-required (module-mass)
+ (iterate
+ (for fuel :first (fuel-required module-mass) :then (fuel-required fuel))
+ (summing fuel)
+ (until (zerop fuel))))
+
+(define-problem (2019 1) (data read-all)
+ (values (summation data :key #'fuel-required)
+ (summation data :key #'complete-fuel-required)))
+
+(define-problem-tests (2019 1) 3464458 1)
--- a/src/utils.lisp Fri Nov 29 15:15:05 2019 -0500
+++ b/src/utils.lisp Sun Dec 01 11:39:22 2019 -0500
@@ -49,6 +49,15 @@
:name (format nil "~2,'0D" day)
:type "txt"))
+(defmacro define-problem-tests ((year day) part1 part2)
+ `(1am:test ,(alexandria:symbolicate 'test-
+ (princ-to-string year)
+ '/
+ (princ-to-string day))
+ (multiple-value-bind (part1 part2) (,(alexandria:symbolicate 'run))
+ (1am:is (= ,part1 part1))
+ (1am:is (= ,part2 part2)))))
+
;;;; Readers ------------------------------------------------------------------
(defun read-numbers-from-line (line)