Finish the stupid goddamn pots
author |
Steve Losh <steve@stevelosh.com> |
date |
Sun, 16 Dec 2018 19:28:52 -0500 |
parents |
a19c9e1fd077 |
children |
5b5c61ad8d2b |
(defpackage :advent/2018/05 #.cl-user::*advent-use*)
(in-package :advent/2018/05)
(named-readtables:in-readtable :interpol-syntax)
(defun reactivep (x y)
(char= x (char-invertcase y)))
(defun react (string &aux result)
(doseq (char string)
(if (and result (reactivep char (car result)))
(pop result)
(push char result)))
(coerce (nreverse result) 'string))
(define-problem (2018 5) (data alexandria:read-stream-content-into-string)
(deletef data #\newline)
(values
(length (react data))
(iterate
(for unit :in-vector (remove-duplicates data :test #'char-equal))
(for candidate = (react (remove unit data :test #'char-equal)))
(minimizing (length candidate)))))
(1am:test test-2018/05
(multiple-value-bind (part1 part2) (run)
(1am:is (= 10708 part1))
(1am:is (= 5330 part2))))