Skip to content

Instantly share code, notes, and snippets.

@death
Created December 5, 2017 12:16
Show Gist options
  • Save death/927a6b0da136d69a12d8913882375d9b to your computer and use it in GitHub Desktop.
Save death/927a6b0da136d69a12d8913882375d9b to your computer and use it in GitHub Desktop.
;;;; +----------------------------------------------------------------+
;;;; | 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