diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-12-03 12:21:46 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-12-03 12:21:46 +0100 |
commit | 278956ae9652193a2231614b533417eefb1523cb (patch) | |
tree | c0f4ef66b4be9bbf511d2a1cba7c2691d782e307 | |
parent | 9a76ba31c25d5adfacc41d5c7282fc48fe1113a6 (diff) | |
download | adventofcode2021-278956ae9652193a2231614b533417eefb1523cb.tar.gz adventofcode2021-278956ae9652193a2231614b533417eefb1523cb.tar.xz adventofcode2021-278956ae9652193a2231614b533417eefb1523cb.zip |
day02
-rw-r--r-- | day02 | 1000 | ||||
-rw-r--r-- | day02.bqn | 16 | ||||
-rw-r--r-- | day02.clj | 35 |
3 files changed, 1051 insertions, 0 deletions
diff --git a/day02 b/day02 new file mode 100644 index 0000000..26e4fc2 --- /dev/null +++ b/day02 @@ -0,0 +1,1000 @@ +forward 4 +down 7 +down 4 +forward 2 +down 4 +down 9 +down 1 +forward 1 +down 4 +up 5 +forward 5 +down 3 +forward 5 +forward 6 +down 5 +down 3 +forward 8 +up 7 +forward 1 +forward 5 +forward 7 +up 2 +up 7 +down 1 +down 6 +forward 7 +forward 6 +down 7 +up 9 +down 8 +down 3 +down 1 +down 4 +down 3 +forward 7 +down 1 +forward 6 +down 3 +forward 3 +down 6 +forward 5 +down 7 +up 5 +forward 7 +forward 9 +up 1 +forward 5 +down 5 +down 2 +forward 1 +up 7 +down 8 +down 2 +forward 8 +forward 1 +up 1 +up 5 +forward 9 +up 9 +down 5 +down 5 +forward 6 +forward 1 +down 1 +down 3 +up 6 +up 9 +down 6 +down 1 +forward 1 +down 8 +down 3 +down 8 +up 6 +forward 2 +up 8 +down 2 +down 6 +forward 1 +down 2 +down 1 +down 5 +down 8 +forward 8 +down 8 +down 2 +up 1 +up 3 +forward 1 +down 6 +up 5 +forward 5 +up 7 +forward 3 +forward 3 +down 9 +forward 1 +forward 7 +down 1 +down 1 +down 3 +forward 4 +down 4 +forward 2 +up 8 +forward 2 +down 4 +down 2 +up 1 +forward 6 +forward 6 +down 9 +forward 5 +down 3 +forward 5 +down 6 +down 9 +forward 9 +up 6 +down 8 +up 5 +up 2 +forward 5 +down 4 +forward 8 +up 1 +forward 2 +down 9 +down 4 +up 7 +down 1 +down 6 +down 7 +down 7 +down 2 +down 2 +up 7 +down 1 +up 7 +up 4 +forward 9 +down 6 +up 3 +down 5 +forward 8 +up 4 +forward 5 +forward 8 +forward 4 +forward 7 +forward 2 +down 3 +up 4 +forward 7 +forward 3 +down 7 +up 4 +forward 8 +forward 9 +forward 9 +up 6 +up 5 +forward 7 +down 7 +up 5 +down 9 +down 8 +forward 5 +forward 2 +down 1 +down 2 +down 9 +up 5 +down 3 +down 8 +up 6 +forward 9 +down 9 +up 3 +up 9 +forward 3 +forward 9 +down 5 +up 3 +down 6 +forward 5 +down 6 +down 9 +forward 3 +down 7 +down 5 +down 9 +forward 8 +down 8 +forward 8 +forward 2 +up 6 +down 9 +down 7 +down 4 +down 2 +down 9 +forward 7 +up 1 +forward 6 +forward 7 +down 3 +down 5 +down 3 +forward 4 +down 9 +forward 2 +down 1 +forward 4 +up 9 +down 8 +down 9 +forward 5 +up 2 +down 7 +down 2 +down 7 +forward 8 +up 8 +forward 9 +up 8 +down 3 +down 8 +forward 2 +up 7 +forward 4 +up 8 +forward 6 +forward 6 +forward 4 +forward 3 +down 4 +up 7 +down 8 +forward 1 +forward 9 +forward 8 +forward 8 +down 6 +down 6 +down 4 +down 8 +forward 9 +down 8 +down 4 +forward 2 +forward 7 +down 4 +up 1 +down 4 +down 5 +up 5 +up 9 +down 5 +up 5 +forward 2 +down 8 +forward 7 +forward 2 +up 4 +forward 8 +up 7 +down 5 +forward 5 +down 5 +down 6 +down 7 +forward 1 +down 8 +up 8 +up 9 +up 6 +forward 2 +forward 7 +forward 4 +down 6 +up 4 +up 3 +down 3 +forward 7 +up 9 +down 9 +up 5 +forward 1 +up 7 +down 7 +down 7 +up 8 +down 3 +forward 6 +down 6 +down 7 +down 2 +forward 5 +up 8 +up 5 +up 1 +down 5 +forward 9 +forward 9 +forward 2 +forward 6 +up 8 +forward 8 +down 1 +forward 6 +up 7 +up 3 +forward 3 +up 5 +down 8 +forward 2 +down 5 +down 5 +forward 8 +forward 8 +forward 6 +up 7 +up 1 +forward 1 +down 7 +down 1 +up 9 +forward 7 +up 6 +down 2 +down 5 +forward 1 +down 1 +up 1 +forward 7 +forward 7 +forward 1 +up 2 +forward 2 +down 9 +down 8 +forward 9 +forward 8 +up 9 +down 1 +down 3 +up 1 +down 3 +up 9 +down 7 +up 6 +down 1 +down 2 +down 2 +down 4 +forward 4 +forward 3 +down 7 +forward 9 +forward 1 +down 2 +down 2 +down 4 +down 7 +up 7 +forward 6 +forward 2 +down 6 +down 3 +down 3 +down 8 +up 8 +forward 6 +down 8 +down 3 +forward 7 +down 4 +down 4 +up 1 +up 8 +forward 5 +forward 6 +down 8 +down 9 +up 7 +forward 2 +forward 4 +down 4 +forward 6 +forward 5 +down 4 +up 5 +down 5 +forward 1 +down 2 +up 9 +forward 9 +forward 6 +forward 8 +down 2 +down 9 +up 1 +forward 6 +down 3 +forward 6 +forward 7 +down 9 +forward 1 +forward 1 +forward 5 +up 5 +up 6 +forward 8 +forward 6 +forward 6 +forward 8 +down 6 +down 8 +forward 5 +forward 7 +forward 3 +forward 3 +up 5 +forward 8 +up 3 +forward 6 +forward 4 +forward 3 +up 8 +down 1 +down 3 +down 7 +up 8 +forward 5 +down 9 +up 7 +down 2 +down 4 +down 5 +down 2 +up 3 +down 4 +down 4 +forward 4 +forward 6 +up 4 +forward 5 +forward 3 +up 2 +up 3 +down 4 +down 7 +forward 7 +forward 2 +down 2 +forward 5 +up 4 +forward 2 +down 8 +up 5 +up 6 +forward 2 +forward 3 +up 3 +down 2 +forward 7 +down 6 +forward 3 +forward 6 +up 9 +forward 7 +up 1 +forward 1 +forward 2 +down 3 +forward 9 +down 1 +up 5 +up 7 +up 8 +down 5 +up 4 +down 9 +forward 4 +up 8 +forward 3 +forward 7 +down 7 +down 9 +down 5 +up 4 +down 2 +up 5 +down 4 +forward 3 +down 7 +up 5 +forward 9 +forward 9 +forward 7 +up 5 +forward 7 +up 3 +forward 8 +down 1 +down 5 +up 5 +forward 4 +forward 9 +forward 9 +up 5 +down 9 +up 7 +up 3 +forward 5 +down 4 +down 7 +forward 9 +down 9 +up 3 +forward 4 +forward 7 +down 9 +forward 2 +down 2 +forward 1 +down 2 +up 7 +down 6 +forward 9 +forward 1 +down 5 +forward 9 +forward 7 +up 4 +forward 9 +forward 7 +up 4 +down 1 +down 3 +down 3 +down 1 +down 9 +forward 3 +forward 5 +forward 2 +down 1 +forward 9 +down 6 +up 6 +down 7 +down 1 +down 1 +up 1 +up 8 +down 6 +down 3 +down 9 +forward 3 +forward 9 +down 4 +forward 6 +forward 7 +down 3 +forward 5 +up 8 +up 6 +forward 3 +forward 2 +down 6 +up 7 +forward 3 +forward 1 +down 8 +down 1 +forward 1 +forward 2 +up 7 +down 3 +forward 9 +forward 6 +up 8 +forward 3 +down 3 +down 9 +down 3 +down 6 +down 6 +down 2 +forward 8 +down 3 +forward 2 +up 8 +forward 5 +up 6 +down 7 +down 4 +down 2 +up 9 +down 4 +down 9 +down 4 +down 9 +forward 2 +down 5 +down 5 +forward 7 +up 2 +forward 5 +forward 1 +down 4 +forward 6 +forward 9 +down 1 +down 2 +down 6 +forward 5 +up 9 +up 1 +up 9 +up 4 +down 1 +up 3 +down 5 +forward 4 +forward 3 +forward 1 +down 9 +down 9 +down 6 +forward 4 +forward 4 +forward 1 +down 9 +down 8 +down 7 +forward 2 +forward 7 +forward 1 +down 7 +forward 8 +forward 7 +up 4 +down 4 +forward 8 +forward 6 +down 6 +forward 9 +down 2 +forward 7 +forward 1 +down 5 +down 5 +down 3 +down 7 +forward 9 +down 2 +forward 3 +forward 6 +up 4 +up 9 +forward 6 +up 8 +up 2 +forward 9 +forward 3 +forward 9 +down 4 +down 8 +down 1 +down 1 +forward 4 +up 3 +forward 1 +forward 5 +down 5 +down 6 +down 7 +forward 5 +down 3 +up 9 +forward 5 +down 4 +up 9 +forward 1 +down 3 +down 5 +forward 2 +down 7 +up 7 +down 2 +forward 2 +down 2 +down 4 +down 3 +forward 6 +down 7 +down 2 +down 1 +forward 7 +forward 9 +forward 8 +up 8 +forward 5 +down 8 +forward 9 +forward 9 +up 5 +forward 9 +up 8 +up 6 +up 5 +up 3 +down 2 +down 8 +down 4 +up 3 +down 4 +up 8 +down 3 +up 1 +down 4 +down 7 +down 4 +up 7 +down 3 +up 3 +up 8 +forward 3 +down 2 +forward 7 +up 9 +forward 2 +down 1 +down 1 +forward 2 +forward 9 +up 6 +forward 3 +forward 2 +down 1 +down 3 +down 6 +forward 7 +down 4 +forward 2 +down 6 +up 3 +up 5 +forward 6 +up 7 +down 5 +up 5 +forward 5 +down 6 +forward 7 +up 2 +forward 3 +forward 4 +forward 9 +down 4 +down 5 +up 7 +up 1 +down 1 +down 5 +forward 4 +down 2 +down 8 +down 6 +down 3 +down 1 +down 9 +forward 5 +forward 7 +down 5 +forward 7 +down 6 +up 8 +up 9 +down 4 +forward 7 +up 1 +up 5 +down 8 +forward 5 +up 8 +forward 1 +forward 7 +forward 5 +forward 8 +forward 8 +up 1 +down 4 +up 6 +down 1 +down 4 +up 9 +forward 4 +forward 1 +forward 5 +up 7 +forward 5 +forward 7 +up 3 +up 6 +up 3 +forward 4 +down 5 +down 4 +down 2 +down 4 +forward 7 +down 5 +forward 9 +forward 2 +down 3 +up 7 +forward 9 +forward 3 +down 9 +up 8 +forward 1 +forward 3 +up 8 +down 3 +up 9 +down 4 +forward 6 +forward 8 +down 4 +forward 9 +up 1 +forward 3 +forward 1 +up 3 +down 3 +forward 1 +forward 2 +forward 8 +up 3 +down 9 +forward 1 +up 1 +forward 2 +down 4 +forward 7 +up 9 +forward 2 +down 6 +down 8 +up 1 +forward 1 +forward 7 +down 8 +forward 7 +up 9 +up 5 +down 6 +down 2 +down 9 +down 9 +down 7 +down 4 +forward 4 +up 2 +up 8 +forward 5 +down 9 +down 7 +forward 3 +forward 1 +down 3 +down 1 +forward 5 +up 2 +up 9 +up 2 +forward 4 +forward 3 +forward 8 +up 9 +up 6 +up 3 +forward 7 +forward 8 +forward 8 +forward 1 +forward 1 +forward 2 +down 2 +down 7 +forward 4 +up 2 +down 4 +forward 5 +down 3 +forward 1 +down 3 +up 2 +forward 9 +forward 7 +forward 5 +forward 1 +forward 6 +forward 9 +up 3 +down 8 +down 8 +forward 3 +up 4 +up 1 +down 4 +forward 8 +up 9 +down 4 +down 5 +forward 1 +forward 7 +up 2 +down 2 +down 2 +down 1 +up 6 +forward 7 +forward 7 +down 7 +down 8 +forward 1 +forward 8 +down 3 +up 5 +up 9 +down 2 +down 9 +forward 3 +up 8 +up 9 +up 3 +up 3 +forward 9 +up 6 +up 7 +down 6 +down 8 +forward 4 +down 8 +forward 4 +forward 9 +down 9 +forward 4 +up 6 +up 5 +down 2 +forward 6 +down 2 +up 2 +up 4 +forward 4 +forward 6 +down 7 +up 4 +down 8 +forward 1 +down 5 +forward 4 +down 3 +forward 3 +down 5 +forward 7 +down 8 +up 7 +down 7 +forward 1 +forward 6 +up 7 +up 8 +up 2 +forward 1 +forward 1 +down 5 +down 9 +forward 7 +forward 5 +down 7 +up 1 +forward 6 +forward 6 +down 6 +forward 1 +down 1 +down 2 +down 4 +forward 5 +up 7 +up 7 +forward 6 +down 1 +forward 7 diff --git a/day02.bqn b/day02.bqn new file mode 100644 index 0000000..ae2c60d --- /dev/null +++ b/day02.bqn @@ -0,0 +1,16 @@ +d←•FLines"day02" +c←⊑¨d +n←'0'-˜¯1⊑¨d + +pos←+´n×'f'=c +aim←+`n×1-˜"ufd"⊐c +depth←⊑⌽aim +•Out pos×depth + +depth2←+´n×aim×'f'=c +•Out pos×depth2 + +{ # Golfed: +•Out (p←+´m←n×c=9)×⊑⌽a←+`(n←'0'-˜¯1⊑¨d)×1-˜4‿9‿6⊐c←≠¨d←•FLines"day02" +•Out p×+´a×m +} diff --git a/day02.clj b/day02.clj new file mode 100644 index 0000000..3e293ff --- /dev/null +++ b/day02.clj @@ -0,0 +1,35 @@ +(ns org.vuxu.aoc2021.day02 + (:require [clojure.string :as str])) + +(def data + (->> (slurp "day02") + (str/split-lines) + (map (fn [line] + (let [[command amount] (str/split line #" ")] + [(keyword command) (parse-long amount)]))))) + +(def part1 + (->> data + (reduce (fn [state [command amount]] + (case command + :forward (update state :pos + amount) + :up (update state :depth - amount) + :down (update state :depth + amount))) + {:pos 0 :depth 0}) + vals + (apply *))) +;; => 1250395 + +(def part2 + (->> data + (reduce (fn [state [command amount]] + (case command + :forward (-> state + (update :pos + amount) + (update :depth + (* (:aim state) amount))) + :up (update state :aim - amount) + :down (update state :aim + amount))) + {:pos 0 :depth 0 :aim 0}) + ((juxt :pos :depth)) + (apply *))) +;; => 1451210346 |