|
|
@ -11,14 +11,49 @@
|
|
|
|
(provide (rename-out [mb #%module-begin]))
|
|
|
|
(provide (rename-out [mb #%module-begin]))
|
|
|
|
(define-macro (mb . IPS)
|
|
|
|
(define-macro (mb . IPS)
|
|
|
|
#'(#%module-begin
|
|
|
|
#'(#%module-begin
|
|
|
|
(length (filter supports-tls? (list . IPS)))
|
|
|
|
(define ips (list . IPS))
|
|
|
|
(map supports-tls? (list . IPS))))
|
|
|
|
(displayln (format "part a: ~a" (length (filter supports-tls? ips))))
|
|
|
|
|
|
|
|
(displayln (format "part b: ~a" (length (filter supports-ssl? ips))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (supports-tls? x)
|
|
|
|
(define bracketed-pattern #rx"\\[.*?\\]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (bracketed-parts str)
|
|
|
|
|
|
|
|
(regexp-match* bracketed-pattern str))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (unbracketed-parts str)
|
|
|
|
|
|
|
|
(string-split str bracketed-pattern))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (has-abba? str)
|
|
|
|
|
|
|
|
(for*/or ([idx (in-range (string-length str))]
|
|
|
|
|
|
|
|
[substr (in-list (regexp-match* #px"^\\w\\w\\w\\w" str idx))]
|
|
|
|
|
|
|
|
#:when substr)
|
|
|
|
|
|
|
|
(define cs (string->list substr))
|
|
|
|
|
|
|
|
(and
|
|
|
|
|
|
|
|
(char=? (first cs) (fourth cs))
|
|
|
|
|
|
|
|
(char=? (second cs) (third cs))
|
|
|
|
|
|
|
|
(not (char=? (first cs) (second cs))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (supports-tls? str)
|
|
|
|
(and
|
|
|
|
(and
|
|
|
|
(let ([maybe-abbas (regexp-match* #px"(\\w)(\\w)\\2\\1" x)])
|
|
|
|
(ormap has-abba? (unbracketed-parts str))
|
|
|
|
(ormap (λ(ma)
|
|
|
|
(andmap (negate has-abba?) (bracketed-parts str))))
|
|
|
|
(not (equal? (substring ma 0 1) (substring ma 1 2)))) maybe-abbas))
|
|
|
|
|
|
|
|
(let ([maybe-bad-abbas (regexp-match* #px"\\[.*((\\w)(\\w)\\3\\2).*\\]" x #:match-select cadr)])
|
|
|
|
(define (find-abas str)
|
|
|
|
(andmap (λ(ma)
|
|
|
|
(for*/list ([idx (in-range (string-length str))]
|
|
|
|
(equal? (substring ma 0 1) (substring ma 1 2))) maybe-bad-abbas))))
|
|
|
|
[substr (in-list (regexp-match* #px"^\\w\\w\\w" str idx))]
|
|
|
|
|
|
|
|
[cs (in-value (string->list substr))]
|
|
|
|
|
|
|
|
#:when (and
|
|
|
|
|
|
|
|
substr
|
|
|
|
|
|
|
|
(char=? (first cs) (third cs))
|
|
|
|
|
|
|
|
(not (char=? (first cs) (second cs)))))
|
|
|
|
|
|
|
|
substr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (aba->bab aba) (format "~a~a~a" (substring aba 1 2)
|
|
|
|
|
|
|
|
(substring aba 0 1)
|
|
|
|
|
|
|
|
(substring aba 1 2)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (supports-ssl? str)
|
|
|
|
|
|
|
|
(define abas (append-map find-abas (unbracketed-parts str)))
|
|
|
|
|
|
|
|
(for*/or ([bab (in-list (map aba->bab abas))]
|
|
|
|
|
|
|
|
[str (in-list (bracketed-parts str))])
|
|
|
|
|
|
|
|
(regexp-match bab str)))
|
|
|
|