langify
parent
8d3cf51a11
commit
87d3d263d7
@ -0,0 +1,2 @@
|
|||||||
|
#lang aoc-racket/2016/day05
|
||||||
|
ojvtpuvg
|
@ -1,15 +1,25 @@
|
|||||||
#lang br
|
#lang br/quicklang
|
||||||
(require openssl/md5)
|
(require openssl/md5)
|
||||||
|
|
||||||
(define key "ojvtpuvg")
|
(define (read-syntax path port)
|
||||||
|
(strip-bindings
|
||||||
|
#`(module mod "day05.rkt"
|
||||||
|
(solve-part-a #,(string-trim (port->string port))))))
|
||||||
|
(module+ reader (provide read-syntax))
|
||||||
|
|
||||||
(let loop ([idx 0][password-cs empty])
|
(provide #%module-begin)
|
||||||
(cond
|
|
||||||
[(= 8 (length password-cs))
|
(define (solve-part-a key)
|
||||||
(apply string-append (reverse password-cs))]
|
(display "part a solution: ")
|
||||||
[else
|
(for*/fold ([password-cs empty])
|
||||||
(define this-key (format "~a~a" key idx))
|
([idx (in-naturals)]
|
||||||
(define next-hash (md5 (open-input-string this-key)))
|
[this-key (in-value (format "~a~a" key idx))]
|
||||||
(if (string-prefix? next-hash "00000")
|
#:break (= 8 (length password-cs)))
|
||||||
(loop (add1 idx) (cons (substring next-hash 5 6) password-cs))
|
(define this-hash (md5 (open-input-string this-key)))
|
||||||
(loop (add1 idx) password-cs))]))
|
(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)
|
||||||
|
Reference in New Issue