mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
24 lines
771 B
Clojure
24 lines
771 B
Clojure
(ns ^{:doc "Day 6"
|
|
:author "Adam Jeniski"}
|
|
day06 (:require [clojure.string :as string]
|
|
[core :refer [get-puzzle-input]]))
|
|
|
|
(def input (get-puzzle-input 6))
|
|
|
|
(defn solve [num-str-lists] ; takes a list of list of number-strings representing time and distance
|
|
(->> (map (partial map #(Long/parseLong %)) num-str-lists)
|
|
(apply zipmap)
|
|
(map (fn [[ms record]] (->> (range 1 ms)
|
|
(map #(* % (- ms %)))
|
|
(filter #(> % record))
|
|
count)))
|
|
(reduce *)))
|
|
|
|
;; part 1
|
|
(solve (map (partial re-seq #"\d+") input))
|
|
|
|
;; part 2
|
|
(solve (->> (map (partial re-seq #"[\s\d]+") input)
|
|
(map (partial map #(string/replace % " " "")))))
|
|
|