You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2016/day05.rkt

26 lines
767 B
Racket

#lang br/quicklang
(require openssl/md5)
(define (read-syntax path port)
(strip-bindings
#`(module mod "day05.rkt"
(solve-part-a #,(string-trim (port->string port))))))
(module+ reader (provide read-syntax))
(provide #%module-begin)
(define (solve-part-a key)
(display "part a solution: ")
(for*/fold ([password-cs empty])
([idx (in-naturals)]
[this-key (in-value (format "~a~a" key idx))]
#:break (= 8 (length password-cs)))
(define this-hash (md5 (open-input-string this-key)))
(if (string-prefix? this-hash "00000")
(let ([next-str (substring this-hash 5 6)])
(display next-str)
(cons next-str password-cs))
password-cs))
(displayln ""))
(provide solve-part-a)