Finished problem 4 of 2015 in racket
This commit is contained in:
20
2015/puzzle-4.rkt
Normal file
20
2015/puzzle-4.rkt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require racket/file)
|
||||||
|
(require file/md5)
|
||||||
|
|
||||||
|
(define input (file->string "4-input"))
|
||||||
|
|
||||||
|
(define (find-salt requested-string current)
|
||||||
|
(let* ([full-message (string-append input (number->string current))]
|
||||||
|
[hash (bytes->string/locale (md5 full-message))])
|
||||||
|
(if (string-prefix? hash requested-string)
|
||||||
|
current
|
||||||
|
(find-salt requested-string (+ current 1)))))
|
||||||
|
|
||||||
|
(printf "Round 1: ~a~%" (find-salt "00000" 0))
|
||||||
|
(printf "Round 2: ~a~%" (find-salt "000000" 0))
|
||||||
|
|
||||||
|
;; Local Variables:
|
||||||
|
;; compile-command: "racket puzzle-4.rkt"
|
||||||
|
;; End:
|
||||||
Reference in New Issue
Block a user