Skip to content

Instantly share code, notes, and snippets.

@winny-

winny-/day4.rkt Secret

Created December 10, 2017 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winny-/0db16f44fc12f0fc9bc07d567b753f66 to your computer and use it in GitHub Desktop.
Save winny-/0db16f44fc12f0fc9bc07d567b753f66 to your computer and use it in GitHub Desktop.
#lang racket
(define (read-passphrase ip)
(match (read-line)
[(? eof-object?) eof]
[a (string-split a)]))
(define (valid1? passphrase)
(for/and ([p passphrase])
(= 1 (count (curry string=? p) passphrase))))
(define (part1 passphrases)
(count valid1? passphrases))
(define (valid2? passphrase)
(valid1? (map (compose1 list->string (curryr sort char<?) string->list) passphrase)))
(define (part2 passphrases)
(count valid2? passphrases))
(module+ main
(define passphrases (port->list read-passphrase))
(displayln (format "Part 1: ~a" (part1 passphrases)))
(displayln (format "Part 2: ~a" (part2 passphrases))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment