Compare commits

..

2 Commits

Author SHA1 Message Date
de3c367d1c do 2015 day 5 pt1 2025-11-27 07:17:43 -10:00
171a4d285d do 2015 day4 2025-11-27 07:17:23 -10:00
2 changed files with 35 additions and 0 deletions

21
2015/src/day04.clj Normal file
View 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")

14
2015/src/day05.clj Normal file
View File

@ -0,0 +1,14 @@
(ns day05
(:require [input-manager]
[clojure.string :as str]))
(def input (input-manager/get-input 2015 5))
(def bad #{"ab" "cd" "pq" "xy"})
;; part 1
(count (filter #(and (not (some (partial str/includes? %) bad))
(>= (count (filter #{\a \e \i \o \u} %)) 3)
(some (partial apply =) (concat (partition 2 %)
(partition 2 (rest %)))))
input))