about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day171
-rw-r--r--day17.bqn10
-rw-r--r--day17.clj36
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