-
-
Save winny-/0db16f44fc12f0fc9bc07d567b753f66 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
#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