mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 10:22:43 -10:00
Compare commits
2 Commits
66c7ee02d4
...
de3c367d1c
| Author | SHA1 | Date | |
|---|---|---|---|
| de3c367d1c | |||
| 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")
|
||||
14
2015/src/day05.clj
Normal file
14
2015/src/day05.clj
Normal 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))
|
||||
Loading…
x
Reference in New Issue
Block a user