Author: Honza Pokorny <honza@pokorny.ca>
cleanup
resources/input11.txt | 99 +++++ resources/input12.txt | 764 +++++++++++++++++++++++++++++++++++++++++++++ resources/input13.txt | 2 src/aoc/core.clj | 6 src/aoc/day01.clj | 2 src/aoc/day02.clj | 2 src/aoc/day04.clj | 5 src/aoc/day07.clj | 1 src/aoc/day11.clj | 118 ++++++ src/aoc/day12.clj | 155 +++++++++ src/aoc/day13.clj | 121 +++++++ template.clj | 25 +
diff --git a/resources/input11.txt b/resources/input11.txt new file mode 100644 index 0000000000000000000000000000000000000000..85142c6dfa1d49b11cd3b35a2c3794e04fb2e248 --- /dev/null +++ b/resources/input11.txt @@ -0,0 +1,99 @@ +LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.L.LLLLL.LLLL.LLLLLLLLL..LLL.LLLLLLLLLLLLLL.LLLLLLLLL.LLL.LLLLLL +LLLLLLLLLL.L.LLLLLLL.LL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLL.LLLLLL +LLLLLLLL.L.LLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLL.LLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLL.LLLLLL +.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLL.LLLLLL.LLLLL.LLL.LLLLLLLLLL.LLLLLL.LLLLLLLL.LLLLLL.LLLLL.LLLLLL +LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLL.LLLLL.LL.LLLLLLLLL.LLLL.LLLLLL.LLLLLLLL.LLLLLLL.LLLL.LLLLLL +LLL.LL..L..L.LL.L.L........L.............LLL....LL...L..L.L.....L..L.L.......L..L......LLLL.L.L +LLLLLLLLLLLLLLLLL..LLLL.LLLLLLL.LLLLLL.LLLLL.LLLLLLLLL.LLLL.LLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLL +LLLLLLLLLL.LLLL.LL.LLLL.LLLLLLLLLLLLLLLLL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LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLL.LLLLLL +...L...L..L.L...L..L......L.......L.L...L...L...L.....L...L...L....L...LL..L..L.............LL. +LLL..LLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLL.LLL.LLLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLLL.LLLLL +LLLLLLLLLL.LLL..LLLLLLL.L.LLLLL.LLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLL.LLL.LLLLLLLLLLLLLLLLLLLLLLLL +LLLLLL.L.L.L.LLLLLLLLLL.LLLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLL.LLLLLL.LLLLLLLL.LLLLLLL.LLLL.LLLLL. +LLLLLL.LLL.LLLLLLLLLLLL.LLLLLLL.L.LLLLLLLLLL.LLLLLLLLL.LLLL.LLLLLL.LLL.LLLL.LLLLLLL.LLLL.LLLLL. +LLLLLLLLLL.LLLLLLL.LLLL.LLLLLLL.LLLLLL.LLLLL.LLL.LLLLL.L.LL.LLLLLL.LLLLLLLL..LLLLLLLLLLL.LLLLLL +LLLLLL.LLL.LLLLLLL.LLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLL.LLLLLLL.LLLLLLLLLLL +LLLLLLLLLL.LLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLL.LLLLLL.LLLLLLL..LLLLLLLLL.LL.LLLLLL +LLLLLLLLLLLLLLLLLLLLLL..LLLLLLL.LLLLLL.LLLLL.LL.LLLLLL.LLLLLLLLLLL.LLLLL.L.LLLLLLLLLLLLL.LLLLLL +LLLLLLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LL.LLLL.LLLL.LLLLLL +.L......L..L........LL..LLL...LL.L.....L..L.L..LLL..LLL..LL.LL...LLL.......L...LL...........LLL +LLLLLLLLLL.LL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LLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLL.LLLLLL +LLLLLLLLL..LLLLLLL.L.LL..LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLL.LLL.LL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL +LLLLLLLLLLLLL.LLLLLLLLL.LLLLLL..LLLLLL.LLLLL.LLLLLLLLLLL.LLLLLLLLLL.LLLLLLL.LLLLLLL.LLLLLLLLLLL +..LLL..L..L...L..L..L.L.....L............L.....L..L....L.LL......L.....L..LLL..L.L..L.......... +LLL.LLLLLL.LLLLLLLLLLLL.LL.LLLLLLLLLLL.LLLLLL.LLLLLLL..LLLL.LLLL.L.L.LLLL.LLLLLLLLLLLLLLLLLLLLL +LLLLLLLLLL.LLLLLLL.LLLL.LLLLLLL.LLLLLL.LL.LL.LLLLLLLLLL.LLL.LL.LLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLL +.LLLLLLLLL.LLLL.LLLLLLLLLLLLL...LL.L.LLLLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL.L.LLLLLL +LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLL.LLLLL.LLL.LLLL.LLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLL +LLLLLLLLLL.LLLLLLL.LLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLLLL.LLLLL.LLL.L.LLLLLLLL.LLLLLL..LLLLLLLLLLL +.LLLLLLLLL.LLLLLLL.LLLL.LLLLLL..LLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLL.LLLL.LLLLLL +.L.....LL......L........L.L....LLL......L...L.LL...L...L..LL................L...L..L........... +LLLLLLLLLL.LLLLLLL.LLLL.LLLL.LL.LLLLLL.LLLL..LLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LL.LLL.LLLLLLL +LLLLLL.LLL.LLLLLL..LLL..LLL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LLLLLLLLLLLLLLLL.LLLL.LLLLLL.LLLLLLLL..LLLLLL.LLLL.L.LLLL diff --git a/resources/input12.txt b/resources/input12.txt new file mode 100644 index 0000000000000000000000000000000000000000..85892eab86ba12ad042e0b4cd9af1b93c915b941 --- /dev/null +++ b/resources/input12.txt @@ -0,0 +1,764 @@ +R90 +W4 +L90 +N2 +E5 +N1 +N5 +R90 +E2 +L90 +F11 +L180 +W4 +L90 +S5 +L90 +F66 +W4 +F2 +E1 +S5 +W5 +F86 +E3 +R90 +N2 +F91 +F94 +R180 +W5 +F18 +R180 +F100 +W5 +F40 +W2 +R180 +F2 +E3 +N4 +W1 +L180 +N3 +E3 +S1 +L180 +W3 +R180 +E2 +F84 +L90 +W1 +N1 +F10 +N4 +R90 +E4 +F55 +S1 +W4 +S5 +W2 +R90 +S5 +E5 +F41 +S1 +W5 +F84 +E3 +F48 +F12 +L90 +F79 +N5 +E2 +F34 +E5 +N2 +F76 +S3 +F73 +W3 +S1 +R180 +W4 +L90 +F9 +E2 +F76 +N3 +F46 +N5 +F41 +S5 +L90 +N3 +L180 +F95 +E3 +R90 +F3 +E4 +F15 +S2 +W5 +R90 +N1 +F26 +F99 +S1 +F13 +F88 +W2 +L90 +W5 +R90 +F2 +E4 +R180 +N2 +F5 +N2 +R90 +S4 +E2 +L90 +F21 +N3 +R90 +E2 +E4 +S1 +W3 +F42 +N3 +E3 +N2 +E1 +L90 +S1 +L90 +F50 +S4 +F24 +S3 +F50 +L90 +F70 +L180 +F19 +N3 +L90 +F18 +L90 +F5 +F70 +R180 +N1 +L90 +E4 +S2 +W3 +N3 +F16 +W5 +F15 +S1 +L180 +S3 +F60 +R180 +F7 +R180 +W4 +R180 +S2 +N5 +W1 +F59 +R90 +S5 +W5 +F80 +L90 +R90 +F62 +R180 +S3 +R180 +W3 +L90 +N2 +F64 +E4 +R180 +S4 +R90 +E3 +F27 +W4 +R90 +F45 +L90 +N1 +E3 +F12 +L180 +F83 +S1 +W5 +L270 +E5 +F97 +F45 +N1 +F16 +F85 +E4 +S2 +N1 +E3 +F41 +N2 +R90 +S2 +R180 +E5 +L270 +F22 +W2 +R180 +N3 +R270 +E5 +L90 +S2 +W5 +F57 +L90 +L90 +F96 +E1 +S4 +W1 +L90 +W1 +F20 +N5 +E4 +R90 +W3 +S5 +R90 +W4 +R270 +F91 +E5 +L90 +F19 +L90 +S4 +R90 +S4 +F58 +R180 +F78 +R180 +F16 +W4 +R90 +F13 +S3 +E3 +F14 +N4 +E4 +R90 +W3 +S4 +W5 +F53 +R90 +S5 +F67 +L90 +W5 +F97 +R90 +W3 +F82 +N5 +F92 +E3 +R90 +F55 +W1 +F100 +E3 +F88 +S2 +E3 +N4 +E1 +F75 +F2 +L180 +E5 +L90 +F40 +N2 +R90 +F25 +N2 +L90 +E4 +F15 +L90 +S3 +W2 +R90 +E2 +R90 +S5 +L90 +F14 +W1 +L180 +F19 +R180 +W4 +S1 +L90 +F14 +N5 +N3 +L90 +N2 +F78 +L90 +N5 +E3 +N2 +F73 +S2 +F88 +N3 +F42 +S5 +F38 +S4 +F73 +R90 +F45 +R90 +F98 +L90 +W5 +S4 +L90 +E3 +L90 +F32 +N2 +F32 +W5 +S1 +R180 +F76 +W1 +L180 +W2 +S1 +R180 +S2 +F1 +S1 +E2 +R90 +N3 +E4 +L90 +S5 +L270 +N2 +F83 +L90 +F53 +L90 +F100 +W1 +L90 +E4 +R90 +S4 +F41 +W2 +R270 +E4 +F65 +R90 +F39 +E5 +R180 +F1 +W2 +R180 +E5 +L270 +E3 +R90 +W3 +R90 +W5 +F17 +E4 +F18 +S2 +N5 +E5 +L90 +W4 +F1 +S4 +E4 +L90 +S3 +E4 +F62 +R180 +F52 +S3 +F10 +S5 +L90 +F28 +R90 +F49 +W3 +F9 +N3 +W2 +N1 +L90 +L90 +E2 +S2 +W2 +F47 +R180 +E1 +R90 +F39 +E3 +N2 +W2 +F86 +F94 +R90 +S2 +R90 +E3 +F88 +N3 +E4 +L90 +S5 +F63 +W5 +L180 +N5 +N2 +F34 +R90 +F19 +N1 +F95 +L90 +E5 +L90 +F3 +R180 +S4 +L90 +F1 +N4 +R90 +E5 +N5 +R90 +E3 +F21 +R180 +S2 +R90 +N2 +L90 +N2 +W2 +E4 +S2 +E1 +N3 +R90 +W1 +L90 +F42 +W4 +F98 +W4 +L90 +F84 +S4 +F67 +W2 +S2 +L90 +S4 +E5 +L90 +F58 +E1 +S1 +W4 +N3 +W3 +R90 +E3 +F19 +S4 +L180 +N3 +R90 +N5 +F77 +N5 +W2 +S1 +L180 +F78 +W5 +S5 +E3 +N2 +F64 +L180 +F21 +R90 +W2 +F44 +N2 +L90 +F91 +S4 +R180 +N2 +W2 +F77 +S5 +F50 +R90 +F21 +W5 +L180 +S4 +F71 +E1 +N4 +R90 +F93 +W1 +N2 +F23 +E4 +L180 +F11 +E4 +F17 +R180 +N3 +R90 +F92 +R180 +F97 +S1 +E1 +F67 +E4 +R90 +F5 +F8 +L180 +L180 +L90 +N3 +N3 +R180 +E2 +F21 +L180 +N1 +S3 +L90 +W1 +L90 +E4 +R90 +F75 +R90 +W3 +F93 +L90 +S4 +F35 +F72 +S5 +E3 +F7 +S3 +R90 +W2 +R90 +F21 +W3 +N5 +F70 +W5 +N2 +L270 +F69 +L90 +S2 +F88 +W5 +S4 +R180 +E2 +F52 +N1 +F93 +N2 +E5 +S4 +L90 +N4 +R90 +F65 +S4 +L180 +S3 +F8 +E4 +R90 +F76 +E3 +F33 +R90 +N2 +F25 +N4 +E1 +S2 +L90 +N1 +L90 +N5 +R90 +E5 +F81 +N5 +F3 +W4 +S1 +F45 +W1 +F43 +E4 +N1 +F45 +E4 +S4 +E4 +N2 +E2 +F15 +W1 +L270 +F84 +R90 +N1 +F21 +N2 +F26 +W1 +N1 +W4 +S4 +F25 +R90 +N5 +R90 +S2 +R90 +E2 +L180 +N4 +R270 +S3 +F46 +S4 +S2 +L90 +N2 +F7 +W1 +S1 +L270 +E2 +R180 +S1 +W4 +N1 +F65 +L90 +E1 +N1 +R90 +N3 +W1 +F47 +R90 +F95 +S4 +L270 +F21 +W4 +S3 +F55 +E2 +N2 +F85 +N2 +R90 +E2 +F8 +S2 +W2 +R90 +W4 +F54 +E4 +F76 +N2 +F5 +F50 +N3 +R180 +W3 +S4 +E1 +L90 +S4 +W1 +F8 diff --git a/resources/input13.txt b/resources/input13.txt new file mode 100644 index 0000000000000000000000000000000000000000..78137a2f0556423c156c823ef0328e3bd353a303 --- /dev/null +++ b/resources/input13.txt @@ -0,0 +1,2 @@ +1005162 +19,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,823,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,443,x,x,x,x,x,37,x,x,x,x,x,x,13 diff --git a/src/aoc/core.clj b/src/aoc/core.clj index 5e738f4897f54572cff41ae3c096fa75cc098eff..5ddabcb526200731ceb11d493d20e53c6dbc951d 100644 --- a/src/aoc/core.clj +++ b/src/aoc/core.clj @@ -1,7 +1,7 @@ (ns aoc.core - (:gen-class)) + (:gen-class) + (:require [aoc.day13 :as day13])) (defn -main - "I don't do a whole lot ... yet." [& args] - (println "Hello, World!")) + (day13/main)) diff --git a/src/aoc/day01.clj b/src/aoc/day01.clj index 7631b42a348e9e0331be0f9dcf109196919bc51d..19290da98555f562ee0272f29c8aa9f01a45bc56 100644 --- a/src/aoc/day01.clj +++ b/src/aoc/day01.clj @@ -44,5 +44,3 @@ (defn main [] (let [input (read-input)] (println (compute-1 input)) (println (compute-2 input)))) - -(main) diff --git a/src/aoc/day02.clj b/src/aoc/day02.clj index becd7e95d1e05aada5d2962eb60b4bf68211cd12..578f6b5312cffbfe71335bda1d55f8565860d913 100644 --- a/src/aoc/day02.clj +++ b/src/aoc/day02.clj @@ -77,5 +77,3 @@ (defn main [] (let [input (read-input)] (println (compute-1 input)) (println (compute-2 input)))) - -(main) diff --git a/src/aoc/day04.clj b/src/aoc/day04.clj index 9d16cca19bb465a1e41db1f36b82311ff15f4a7c..d22a5faf793c23ae539143623b798b4679c29211 100644 --- a/src/aoc/day04.clj +++ b/src/aoc/day04.clj @@ -1,5 +1,6 @@ (ns aoc.day04 - (:require [clojure.java.io :as io])) + (:require [clojure.java.io :as io] + [clojure.set])) (def fields #{:byr :iyr :eyr :hgt :hcl :ecl :pid :cid}) @@ -86,5 +87,3 @@ (defn main [] (let [input (read-input)] (println (compute-1 input)) (println (compute-2 input)))) - -(main) diff --git a/src/aoc/day07.clj b/src/aoc/day07.clj index e9198658d042efbdeb103cbbb168166e3f15dd6b..798e0a6e50fa7cbb062db0ea1c1b8d457732d961 100644 --- a/src/aoc/day07.clj +++ b/src/aoc/day07.clj @@ -65,7 +65,6 @@ (recur r2))))) (defn count-contents [g c] (let [contents (get-parents g c)] - (println "con" contents) (if (seq contents) (reduce (fn [acc {:keys [color number]}] diff --git a/src/aoc/day11.clj b/src/aoc/day11.clj new file mode 100644 index 0000000000000000000000000000000000000000..b382b3d13e0de31966ea5d029fbf936b40d451cd --- /dev/null +++ b/src/aoc/day11.clj @@ -0,0 +1,118 @@ +(ns aoc.day11 + (:require [clojure.java.io :as io])) + +(def example "L.LL.LL.LL +LLLLLLL.LL +L.L.L..L.. +LLLL.LL.LL +L.LL.LL.LL +L.LLLLL.LL +..L.L..... +LLLLLLLLLL +L.LLLLLL.L +L.LLLLL.LL") + +(declare parse-floor) + +(defn read-input [] + (->> + (io/resource "input11.txt") + slurp + + ;; example + clojure.string/split-lines + parse-floor)) + +(defn adjacent [m [sx sy]] + (for [x [-1 0 1] + y [-1 0 1] + :when (not= [x y] [0 0])] + (let [fx (+ x sx) + fy (+ y sy)] + [[fx fy] (get m [fx fy] :empty)]))) + +(defn visible [m [sx sy]] + (for [x [-1 0 1] + y [-1 0 1] + :when (not= [x y] [0 0])] + (let [fx (+ x sx) + fy (+ y sy)] + (some (fn [[[x y] spot]] + (#{:taken :empty} spot)) + (map (fn [[a b]] + [[a b] (get m [a b] :empty)]) + (rest (iterate + (fn [[xx yy]] [(+ xx x) (+ yy y)]) + [sx sy]))))))) + +(defn taken-adjacent [m [sx sy]] + (filter #(= :taken (second %)) + (adjacent m [sx sy]))) + +(defn taken-visible [m [sx sy]] + (filter #(= :taken %) + (visible m [sx sy]))) + +(defn parse-floor [input] + (into {} + (for [y (range (count input)) + x (range (count (first input)))] + (let [spot (get-in input [y x]) + tile (case spot + \L :empty + \# :taken + \. :floor)] + [[x y] tile])))) + +(defn run [input] + (into {} (map (fn [[[x y] seat]] + (let [taken-count (count (taken-adjacent input [x y]))] + (case seat + :empty [[x y] (if (zero? taken-count) :taken :empty)] + :taken [[x y] (if (>= taken-count 4) :empty :taken)] + [[x y] seat]))) + input))) + +(defn run-2 [input] + (into {} (map (fn [[[x y] seat]] + (let [taken-count (count (taken-visible input [x y]))] + (case seat + :empty [[x y] (if (zero? taken-count) :taken :empty)] + :taken [[x y] (if (>= taken-count 5) :empty :taken)] + [[x y] seat]))) + input))) + +(defn reduce-1 [input] + (loop [input input] + (let [res (run input)] + (if (= input res) + res + (recur res))))) + +(defn reduce-2 [input] + (loop [input input] + (let [res (run-2 input)] + (if (= input res) + res + (recur res))))) + +(defn compute-1 [input] + (->> input + reduce-1 + vals + frequencies + :taken)) + +(defn compute-2 [input] + (->> input + reduce-2 + vals + frequencies + :taken)) + +(defn main [] + (let [input (read-input)] + (println (compute-1 input)) + (println (compute-2 input)))) + +(main) diff --git a/src/aoc/day12.clj b/src/aoc/day12.clj new file mode 100644 index 0000000000000000000000000000000000000000..ebfcc64fc577217da6a45e57b6d8dac4a7834d51 --- /dev/null +++ b/src/aoc/day12.clj @@ -0,0 +1,155 @@ +(ns aoc.day12 + (:require [clojure.java.io :as io])) + +(def example "F10 +N3 +F7 +R90 +F11") + +(def start-pos {:facing :east + :north 0 + :east 0}) + +(def start-pos-2 {:wp {:north 1 + :east 10} + :ship {:north 0 + :east 0}}) + +(defn translate [direction [x y]] + (case direction + :right [y (- x)] + :left [(- y) x])) + +(defn translate-wp [pos direction] + (update-in pos [:wp] (fn [{:keys [north east]}] + (let [[x y] (translate direction [east north])] + {:north y :east x})))) + +(defn parse-inst [[h & body]] + {:direction (case h + \N :north + \E :east + \S :south + \W :west + \F :forward + \L :left + \R :right) + :value (read-string (clojure.string/join body))}) + +(defn read-input [] + (->> + (io/resource "input12.txt") + slurp + ;; example + clojure.string/split-lines + (map parse-inst) + )) + +(defn move [direction value] + (fn [old] + (let [op (case direction + :north + + :south - + :east + + :west -)] + (if (nil? op) + old + (op old value))))) + +(def right-turns (cycle [:east :south :west :north])) +(def left-turns (cycle [:east :north :west :south])) + +(defn turn-count [n] + (case n + 90 1 + 180 2 + 270 3 + 0 0)) + +(defn turn [pos {:keys [value direction]}] + (let [current-direction (:facing pos) + tc (turn-count value) + turns (case direction + :left left-turns + :right right-turns + []) + next-turns (drop-while #(not= current-direction %) turns)] + (nth next-turns tc))) + +(defn move-forward [pos {:keys [value direction]}] + (let [facing (:facing pos) + op (case facing + :north + + :east + + :south - + :west -)] + (if (contains? #{:north :south} facing) + (assoc pos :north (op (:north pos) value)) + (assoc pos :east (op (:east pos) value))))) + +(defn navigate [pos {:keys [value direction]}] + (case direction + :north (update pos :north (move direction value)) + :south (update pos :north (move direction value)) + :east (update pos :north (move direction value)) + :west (update pos :north (move direction value)) + :left (assoc pos :facing (turn pos {:direction direction :value value})) + :right (assoc pos :facing (turn pos {:direction direction :value value})) + :forward (move-forward pos {:direction direction :value value}) + pos)) + +(defn should-move-wp? [direction] + (not= direction :forward)) + +(defn should-move-ship? [direction] + (= direction :forward)) + +(defn move-ship [pos {:keys [value]}] + (let [wx (get-in pos [:wp :east]) + wy (get-in pos [:wp :north]) + pos (update-in pos [:ship :east] #(+ % (* wx value))) + pos (update-in pos [:ship :north] #(+ % (* wy value)))] + pos)) + +;; (move-ship {:wp {:east -1 :north -2} :ship {:east 1 :north 1}} +;; {:value 0}) + +(defn rotate-wp [pos {:keys [value direction]}] + (let [tc (turn-count value)] + (reduce (fn [acc _] + (translate-wp acc direction)) + pos + (range tc)))) + +(defn move-wp [pos {:keys [value direction] :as i}] + (case direction + :north (update-in pos [:wp :north] #(+ % value)) + :south (update-in pos [:wp :north] #(- % value)) + :east (update-in pos [:wp :east ] #(+ % value)) + :west (update-in pos [:wp :east ] #(- % value)) + :right (rotate-wp pos i) + :left (rotate-wp pos i))) + +(defn navigate-2 [pos {:keys [value direction] :as i}] + (cond + (should-move-wp? direction) (move-wp pos i) + (should-move-ship? direction) (move-ship pos i) + :else pos)) + +(defn compute-1 [input] + (let [final (reduce navigate start-pos input)] + (+ (Math/abs (:north final)) + (Math/abs (:east final))))) + +(defn compute-2 [input] + (let [final (reduce navigate-2 start-pos-2 input)] + (+ (Math/abs (get-in final [:ship :north])) + (Math/abs (get-in final [:ship :east]))))) + +(defn main [] + (let [input (read-input)] + (println (compute-1 input)) + (println (compute-2 input)))) + +(main) diff --git a/src/aoc/day13.clj b/src/aoc/day13.clj new file mode 100644 index 0000000000000000000000000000000000000000..0a69a9e96aef542fc05b26aeb6ba34d6e0d04e3c --- /dev/null +++ b/src/aoc/day13.clj @@ -0,0 +1,121 @@ +(ns aoc.day13 + (:require [clojure.java.io :as io])) + +(def example "939 +7,13,x,x,59,x,31,19") + +(defn parse-input [[earliest timetable]] + {:earliest (read-string earliest) + :timetable (->> (clojure.string/split timetable #",") + (remove #{"x"}) + (map read-string))}) + +(defn parse-input-2 [[_ timetable]] + (->> (clojure.string/split timetable #",") + (map read-string))) + +(defn read-input [] + (->> + ;; (io/resource "input13.txt") + ;; slurp + + example + clojure.string/split-lines + parse-input + )) + +(defn short-example [s] + (->> (clojure.string/split s #",") + (map read-string))) + +(defn read-input-2 [] + (->> + ;; (io/resource "input13.txt") + ;; slurp + + example + clojure.string/split-lines + parse-input-2 + )) + +(defn tt [earliest t] + (->> (iterate #(+ t %) 0) + (drop-while #(< % earliest)) + first + (conj [t]) + reverse + vec)) + +(defn infinite-timetables-by-id [timetable] + (->> timetable + (remove symbol?) + (map (fn [t] [t (iterate #(+ t %) 0)])) + (into {}))) + +(defn compute-1 [{:keys [earliest timetable]}] + (let [ + tts (map (partial tt earliest) timetable) + tts (into {} tts) + departure (apply min (keys tts)) + minutes (- departure earliest) + bus-id (tts departure)] + (* minutes bus-id))) + +(defn bus-valid [m t bus] + (cond + (nil? bus) :end + (= bus "x") true + (symbol? bus) true + (zero? t) true + :else + (let [i (get m bus)] + (->> (drop-while #(< % t) i) + first + (= t))))) + +(let [tts (infinite-timetables-by-id [6]) + t 5] + (bus-valid tts t nil) + ) + + +(defn run-2 [tts timetable start-t] + (loop [t start-t + buses timetable] + (let [bus (first buses) + res (bus-valid tts t bus)] + (if (contains? #{:end false} res) + start-t + (recur (inc t) (rest buses)))))) + +(defn compute-2 [timetable] + (let [tts (infinite-timetables-by-id timetable)] + (loop [t 100000000000000] + (println "computing" t) + (let [res (run-2 tts timetable t)] + (if (contains? #{:end} res) + t + (recur (inc t))))))) + + +(defn compute-example [timetable t] + (= (run-2 (infinite-timetables-by-id timetable) + timetable + t) + t)) + +(comment +(compute-example (short-example "67,7,59,61") 754018) +(compute-example (short-example "17,x,13,19") 3417) +(compute-example (short-example "67,x,7,59,61") 779210) +(compute-example (short-example "67,7,x,59,61") 1261476) +(compute-example (short-example "1789,37,47,1889") 1202161486) + ) + +(defn main [] + (let [input (read-input) + input2 (read-input-2)] + (println (compute-1 input)) + (println (compute-2 input2)))) + +;; (main) diff --git a/template.clj b/template.clj new file mode 100644 index 0000000000000000000000000000000000000000..8a08ac6011f4a4875f5e2f4d8deb8bddcfceedbe --- /dev/null +++ b/template.clj @@ -0,0 +1,25 @@ +(ns aoc.dayxx + (:require [clojure.java.io :as io])) + +(defn read-input [] + (->> + (io/resource "inputxx.txt") + io/reader + line-seq + + ;; example + ;; clojure.string/split-lines + )) + +(defn compute-1 [input] + input) + +(defn compute-2 [input] + input) + +(defn main [] + (let [input (read-input)] + (println (compute-1 input)) + (println (compute-2 input)))) + +(main)