diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-12-18 17:07:40 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-12-18 17:07:40 +0100 |
commit | 8ca091e841ae891bfd556cf55e519a1ccf014281 (patch) | |
tree | 912258aed8ab502a3850dafde474c4b826a641b4 | |
parent | 4e8974fb4f97a9535fb51bb7b23cd65025f05ce1 (diff) | |
download | adventofcode2021-8ca091e841ae891bfd556cf55e519a1ccf014281.tar.gz adventofcode2021-8ca091e841ae891bfd556cf55e519a1ccf014281.tar.xz adventofcode2021-8ca091e841ae891bfd556cf55e519a1ccf014281.zip |
day17
-rw-r--r-- | day17 | 1 | ||||
-rw-r--r-- | day17.bqn | 10 | ||||
-rw-r--r-- | day17.clj | 36 |
3 files changed, 47 insertions, 0 deletions
diff --git a/day17 b/day17 new file mode 100644 index 0000000..2fd0935 --- /dev/null +++ b/day17 @@ -0,0 +1 @@ +target area: x=209..238, y=-86..-59 diff --git a/day17.bqn b/day17.bqn new file mode 100644 index 0000000..f85adbf --- /dev/null +++ b/day17.bqn @@ -0,0 +1,10 @@ +lx‿ux←209‿238 ⋄ ly‿uy←¯86‿¯59 + +# •Show ÷⟜2 (⊣ × -⟜1) |⊑y +•Show +´↕|ly + +Check ← { ⟨⟨x,y⟩,⟨vx,vy⟩⟩: { (lx≤x)∧(x≤⊑ux)∧(ly≤y)∧(y≤uy) ? 1 ; + y < ly ? 0 ; + Check ⟨⟨x+vx, y+vy⟩, ⟨vx-×vx, vy-1⟩⟩ } } + +•Show +´ ⥊ {Check ⟨0,0⟩‿𝕩}¨ (<1⋈ly)+↕⟨ux,2×|ly⟩ diff --git a/day17.clj b/day17.clj new file mode 100644 index 0000000..be972ba --- /dev/null +++ b/day17.clj @@ -0,0 +1,36 @@ +(ns org.vuxu.aoc2021.day17 + (:require [clojure.string :as str])) + +(def data + (->> (slurp "day17") + (re-seq #"-?\d+") + (map parse-long))) + +(def x-range (take 2 data)) +(def y-range (drop 2 data)) + +(def part1 + (quot (* (Math/abs (first y-range)) + (dec (Math/abs (first y-range)))) 2)) +;; => 3655 + +(defn check [[x y] [vx vy]] + (cond + (and (<= (first x-range) x (second x-range)) + (<= (first y-range) y (second y-range))) + true + + (< y (first y-range)) + false + + :else + (recur [(+ x vx) (+ y vy)] + [(- vx (Integer/signum vx)) (dec vy)]))) + +(def part2 + (count + (filter identity + (for [vx (range (inc (second x-range))) + vy (range (first y-range) (inc (Math/abs (first y-range))))] + (check [0 0] [vx vy]))))) +;; => 1447 |