Compare commits
No commits in common. "04a861dfb96083745a27e80e77a413c1a4475766" and "5ba3b822e14bead169fe928ad6fa7426d674c158" have entirely different histories.
04a861dfb9
...
5ba3b822e1
20
main.clj
20
main.clj
@ -1,26 +1,12 @@
|
|||||||
(ns main
|
(ns main
|
||||||
"Advent Of Code 2023 solved in Clojure"
|
"Advent Of Code 2023 solved in Clojure"
|
||||||
(:require
|
(:require
|
||||||
[day01]
|
[day01]))
|
||||||
[day02])
|
|
||||||
(:import
|
|
||||||
[java.time Instant Duration]))
|
|
||||||
|
|
||||||
(defn benchmark
|
|
||||||
[f day part]
|
|
||||||
(let [then (Instant/now)
|
|
||||||
result (f)
|
|
||||||
now (Instant/now)
|
|
||||||
time (.toMillis (Duration/between then now))]
|
|
||||||
(println (str "Day " day " part " part ": " result " (" time " ms)"))))
|
|
||||||
|
|
||||||
(defn aoc-23 []
|
(defn aoc-23 []
|
||||||
(printf "Advent of Code 2023, solved in Clojure.\n\n")
|
(printf "Advent of Code 2023, solved in Clojure.\n\n")
|
||||||
(benchmark day01/part1 "01" "1")
|
(println (str "Day 01 part 1: " (day01/part1)))
|
||||||
(benchmark day01/part2 "01" "2")
|
(println (str "Day 01 part 2: " (day01/part2))))
|
||||||
(benchmark day02/part1 "02" "1")
|
|
||||||
(benchmark day02/part2 "02" "2")
|
|
||||||
(println "\nthe end."))
|
|
||||||
|
|
||||||
(aoc-23)
|
(aoc-23)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
(def contents (utils/read-file "01" false))
|
(def contents (utils/read-file "01" false))
|
||||||
|
|
||||||
; Vector of String
|
; Vector of String
|
||||||
(def lines ":: Vector of String" (clojure.string/split-lines contents))
|
(def lines "Vector of String" (clojure.string/split-lines contents))
|
||||||
|
|
||||||
; Char -> Bool
|
; Char -> Bool
|
||||||
(defn is-digit? [c]
|
(defn is-digit? [c]
|
||||||
@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
; tests every character on every number
|
; tests every character on every number
|
||||||
(defn sanitize-2
|
(defn sanitize-2
|
||||||
":: String -> String"
|
"String -> String"
|
||||||
[input] (reduce (fn [acc str-pos]
|
[input] (reduce (fn [acc str-pos]
|
||||||
; find which, if any, of the patterns matches on this pos
|
; find which, if any, of the patterns matches on this pos
|
||||||
; match :: Maybe (String String)
|
; match :: Maybe (String String)
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
(ns day02
|
|
||||||
"Day 02 funtions"
|
|
||||||
(:require
|
|
||||||
[utils]
|
|
||||||
[clojure.string]))
|
|
||||||
|
|
||||||
(def contents ":: String" (utils/read-file "01" false))
|
|
||||||
(def lines ":: Vector of String" (clojure.string/split-lines contents))
|
|
||||||
|
|
||||||
; cubes: red, green, blue
|
|
||||||
; the Elf will reach into the bag, grab a handful of random cubes,
|
|
||||||
; show them to you, and then put them back in the bag. He'll do this a few times per game
|
|
||||||
;
|
|
||||||
; Each game is listed with its ID number followed by a semicolon-separated list
|
|
||||||
; of subsets of cubes that were revealed from the bag
|
|
||||||
;
|
|
||||||
; Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
|
||||||
;
|
|
||||||
; Determine which games would have been possible if the bag had been loaded
|
|
||||||
; with only 12 red cubes, 13 green cubes, and 14 blue cubes
|
|
||||||
|
|
||||||
(defn part1
|
|
||||||
":: () -> String"
|
|
||||||
[]
|
|
||||||
"")
|
|
||||||
|
|
||||||
(defn part2
|
|
||||||
":: () -> String"
|
|
||||||
[]
|
|
||||||
"")
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user