aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-11-01 02:32:49 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-11-01 02:32:49 +0000
commit928dcb5572d7c290594625c82b06b4faaa0d712f (patch)
tree3b416b7e5b5985ec485ee34a46ac2920965eb244
parentbbc5da95e722001b92cf2978476ff79c577f952a (diff)
downloadadvent-of-code-928dcb5572d7c290594625c82b06b4faaa0d712f.tar.gz
advent-of-code-928dcb5572d7c290594625c82b06b4faaa0d712f.tar.bz2
advent-of-code-928dcb5572d7c290594625c82b06b4faaa0d712f.zip
Finished problem 4 of 2015 in racket
-rw-r--r--2015/puzzle-4.rkt20
1 files changed, 20 insertions, 0 deletions
diff --git a/2015/puzzle-4.rkt b/2015/puzzle-4.rkt
new file mode 100644
index 0000000..6641bff
--- /dev/null
+++ b/2015/puzzle-4.rkt
@@ -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: