Created
December 5, 2017 12:16
-
-
Save death/927a6b0da136d69a12d8913882375d9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; +----------------------------------------------------------------+ | |
;;;; | Advent of Code 2017 | | |
;;;; +----------------------------------------------------------------+ | |
(defpackage #:snippets/aoc2017/day4 | |
(:use #:cl) | |
(:import-from #:split-sequence #:split-sequence) | |
(:export | |
#:day4)) | |
(in-package #:snippets/aoc2017/day4) | |
(defun split-passphrase (passphrase) | |
(split-sequence #\Space passphrase)) | |
(defun contains-duplicates-p (list &optional key) | |
(> (length list) | |
(length (remove-duplicates list :test 'equal :key key)))) | |
(defun valid-passphrase-p (passphrase &optional key) | |
(not (contains-duplicates-p (split-passphrase passphrase) key))) | |
(defun canonicalize (word) | |
(sort (copy-seq word) #'char<)) | |
(defun day4 (puzzle &optional key) | |
(with-input-from-string (stream puzzle) | |
(loop for passphrase = (read-line stream nil nil) | |
while passphrase | |
count (valid-passphrase-p passphrase key)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment