# HG changeset patch # User Steve Losh # Date 1543695967 18000 # Node ID ff5234e0e3292bd6de434bb562fc2987c050a426 # Parent bc917916aa2bc9e5ece91799c19fcf19415fffc3 Clean up diff -r bc917916aa2b -r ff5234e0e329 README.markdown --- 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 diff -r bc917916aa2b -r ff5234e0e329 src/2018/main.lisp --- 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))))