Created
November 6, 2019 14:11
-
-
Save ynonp/04d9b24d9454a09d5442eb1b6ecb2258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns aoc2018.day5 | |
(:require [clojure.string :as s])) | |
(def letters (map char (concat (range 97 123)))) | |
(def reactions | |
(re-pattern | |
(s/join "|" | |
(for [letter letters] | |
(str | |
letter | |
(s/upper-case letter) | |
"|" | |
(s/upper-case letter) | |
letter))))) | |
(defn remove-all-units | |
[input unit] | |
(s/replace | |
(s/replace input (s/upper-case unit) "") | |
(str unit) | |
"")) | |
(defn reduced-size | |
[input] | |
(if (re-find reactions input) | |
(recur (s/replace input reactions "")) | |
(count input))) | |
(defn size-without-unit | |
[input unit] | |
(reduced-size (remove-all-units input unit))) | |
(defn part2 | |
[] | |
(let [ | |
input (s/trim-newline (slurp "inputs/day5.txt")) | |
spoiler (apply min-key (partial size-without-unit input) letters)] | |
(println "hello") | |
(println (size-without-unit input spoiler)) | |
(println "the end"))) | |
(defn part1 | |
[] | |
(let [input (s/trim-newline (slurp "inputs/day5.txt"))] | |
(println (reduced-size input)))) | |
(part2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment