mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 07:03:19 -09:00
its beginning to look a lot like christmas 2023
This commit is contained in:
parent
fdd5179d31
commit
c247628752
6
2023/.gitignore
vendored
Normal file
6
2023/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.clj-kondo
|
||||||
|
.cpcache
|
||||||
|
.lsp
|
||||||
|
.nrepl-port
|
||||||
|
session
|
||||||
|
|
4
2023/README.md
Normal file
4
2023/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
## Clojure Project Template
|
||||||
|
|
||||||
|
a quickstart project to get going using cider/nrepl & babashka tasks
|
||||||
|
|
3
2023/bb.edn
Normal file
3
2023/bb.edn
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{:paths ["script"]
|
||||||
|
:min-bb-version "0.4.0"
|
||||||
|
:tasks {nrepl (shell "clj -M:repl --port 5555")}}
|
11
2023/deps.edn
Normal file
11
2023/deps.edn
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{:paths ["src" "resources"]
|
||||||
|
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
|
||||||
|
org.clojure/core.match {:mvn/version "1.0.1"}
|
||||||
|
clj-http/clj-http {:mvn/version "3.12.3"}}
|
||||||
|
:aliases
|
||||||
|
{:repl
|
||||||
|
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}
|
||||||
|
cider/cider-nrepl {:mvn/version "0.28.4"}}
|
||||||
|
:main-opts ["-m" "nrepl.cmdline"
|
||||||
|
"--middleware" "[cider.nrepl/cider-middleware]"
|
||||||
|
"--interactive"]}}}
|
18
2023/src/core.clj
Normal file
18
2023/src/core.clj
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
(ns core
|
||||||
|
(:require [clj-http.client :as client]
|
||||||
|
[clojure.string :as string]))
|
||||||
|
|
||||||
|
(def input-cache (atom {}))
|
||||||
|
(def cookie (str "session=" (slurp "session")))
|
||||||
|
|
||||||
|
(defn get-puzzle-input [day]
|
||||||
|
(or (@input-cache day)
|
||||||
|
(swap! input-cache assoc day
|
||||||
|
(-> (str "https://adventofcode.com/2023/day/" day "/input")
|
||||||
|
(client/get {:throw-entire-message? true
|
||||||
|
:headers {"Cookie" cookie}})
|
||||||
|
:body
|
||||||
|
string/split-lines))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
input-cache)
|
38
2023/src/day01.clj
Normal file
38
2023/src/day01.clj
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
(ns ^{:doc "Day 1"
|
||||||
|
:author "Adam Jeniski"}
|
||||||
|
day01 (:require [core :refer [get-puzzle-input]]
|
||||||
|
[clojure.string :as string]))
|
||||||
|
|
||||||
|
(def input (get-puzzle-input 1))
|
||||||
|
|
||||||
|
(def numeric-value-map {"one" 1
|
||||||
|
"two" 2
|
||||||
|
"three" 3
|
||||||
|
"four" 4
|
||||||
|
"five" 5
|
||||||
|
"six" 6
|
||||||
|
"seven" 7
|
||||||
|
"eight" 8
|
||||||
|
"nine" 9})
|
||||||
|
|
||||||
|
(defn numeric-value [s]
|
||||||
|
(or (numeric-value-map s) s))
|
||||||
|
|
||||||
|
;; part 1
|
||||||
|
(->> input
|
||||||
|
(map (fn [line]
|
||||||
|
{:first (re-find #"\d" line)
|
||||||
|
:last (re-find #"\d" (string/reverse line))}))
|
||||||
|
(map #(str (:first %) (:last %)))
|
||||||
|
(map #(Integer/parseInt %))
|
||||||
|
(reduce +))
|
||||||
|
|
||||||
|
;; part 2
|
||||||
|
(->> input
|
||||||
|
(map (fn [line]
|
||||||
|
(let [f (re-find #"one|two|three|four|five|six|seven|eight|nine|\d" line)
|
||||||
|
l (string/reverse (re-find #"eno|owt|eerht|ruof|evif|xis|neves|thgie|enin|\d" (string/reverse line)))]
|
||||||
|
(str (numeric-value f) (numeric-value l)))))
|
||||||
|
(map #(Integer/parseInt %))
|
||||||
|
(reduce +))
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user