mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 11:02:45 -10:00
do 2015 day4
This commit is contained in:
parent
66c7ee02d4
commit
171a4d285d
21
2015/src/day04.clj
Normal file
21
2015/src/day04.clj
Normal file
@ -0,0 +1,21 @@
|
||||
(ns day04
|
||||
(:require [input-manager]
|
||||
[clojure.set])
|
||||
(:import java.security.MessageDigest java.math.BigInteger))
|
||||
|
||||
(def input (input-manager/get-input-raw 2015 4))
|
||||
|
||||
(defn string->md5 [s]
|
||||
(let [algorithm (MessageDigest/getInstance "MD5")
|
||||
raw (.digest algorithm (.getBytes s))]
|
||||
(format "%032x" (BigInteger. 1 raw))))
|
||||
|
||||
(defn solution [target-prefix]
|
||||
(loop [i 0]
|
||||
(let [md5 (string->md5 (str input i))]
|
||||
(if (.startsWith md5 target-prefix)
|
||||
i
|
||||
(recur (inc i))))))
|
||||
|
||||
(solution "00000")
|
||||
(solution "000000")
|
||||
Loading…
x
Reference in New Issue
Block a user