/aoc24

Advent of Code 2024 - Clojure solutions.

Primary LanguageClojureOtherNOASSERTION

Advent of Code 2024

Clojure CI codecov

This year I am taking on the challenges in Clojure.

To use, add a profiles.clj file with the following data:

{:dev {:env {:aoc-session "53616c7... "}}}

You'll need to step through and execute (C-x C-e) most of the solutions step by step with a REPL.

(comment
  (= 2 (count-trues (map is-level-safe? (str->matrix sample)))) ; test case
  (count-trues (map is-level-safe? (str->matrix input)))) ; correct!

Solutions

(->>
 (s/split day-3-input #"do")
 (filter #(not (s/starts-with? % "n't")))
 (apply str)
 (re-seq #"mul\((\d+),(\d+)\)")
 (map #(* (str->int (nth % 1)) (str->int (nth % 2))))
 (apply +)) ; correct!
(defn day-4-answer [input]
  (let [rows (get-rows input)
        cols (get-columns input)
        diag-se (get-diagonal-rows-se input)
        diag-sw (get-diagonal-rows-sw input)
        combined (flatten (apply merge rows cols diag-se diag-sw))
        reversed (map #(apply str (reverse %)) combined)
        all (flatten (apply merge combined reversed))]

    (count (re-seq #"XMAS" (s/join "-" all)))))

License

Copyright © 2024 Ryan Fleck

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

Code Coverage

Unit tests aren't critical to this project, but visualizations are still cool:

Code Coverage Tree