ff5234e0e329

Clean up
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 01 Dec 2018 15:26:07 -0500
parents bc917916aa2b
children 388494359561
branches/tags (none)
files README.markdown src/2018/main.lisp

Changes

--- a/README.markdown	Sat Dec 01 15:11:51 2018 -0500
+++ b/README.markdown	Sat Dec 01 15:26:07 2018 -0500
@@ -1,3 +1,6 @@
-Solutions to http://adventofcode.com/ in Common Lisp.
+My solutions to [Advent of Code](http://adventofcode.com/) in Common Lisp.  They
+make heavy use of my own [personal utility
+library](https://github.com/sjl/cl-losh) and
+[Iterate](https://common-lisp.net/project/iterate/).
 
 License: MIT/X11
--- a/src/2018/main.lisp	Sat Dec 01 15:11:51 2018 -0500
+++ b/src/2018/main.lisp	Sat Dec 01 15:26:07 2018 -0500
@@ -7,16 +7,17 @@
        (let ((,data-symbol (,reader ,(format nil "data/2018/~2,'0D.txt" day))))
          ,@body))))
 
+
 ;;;; Problems -----------------------------------------------------------------
 (define-problem (1 1) (data read-all-from-file)
-  (reduce #'+ data))
+  (summation data))
 
 (define-problem (1 2) (data read-all-from-file)
-  (let ((seen (make-hash-set :initial-contents '(0)))
-        (frequency 0))
-    (setf (cdr (last data)) data) ; make data a circular list for easy repetition
-    (dolist (number data)
-      (incf frequency number)
-      (if (hset-contains-p seen frequency)
-        (return frequency)
-        (hset-insert! seen frequency)))))
+  (setf (cdr (last data)) data) ; make data a circular list for easy looping
+  (iterate
+    (with seen = (make-hash-set :initial-contents '(0)))
+    (for number :in data)
+    (summing number :into frequency)
+    (if (hset-contains-p seen frequency)
+      (return frequency)
+      (hset-insert! seen frequency))))