about summary refs log tree commit diff
path: root/users/sterni/exercises
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-12-10T18·28+0100
committerclbot <clbot@tvl.fyi>2022-12-10T18·36+0000
commit42a4f1487899b9a23db462d048d22b138957b40c (patch)
tree3fbacdf26fc659b2908ecb6c412a89ee787b107b /users/sterni/exercises
parent7ce6c7363c027a32eebd0da952838de4b28df7a6 (diff)
feat(sterni/aoc/2022): day09 BQN solution r/5402
Change-Id: Idad006eaacbd89827feb5bbd9d6e04605743fca2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7555
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/sterni/exercises')
-rw-r--r--users/sterni/exercises/aoc/2022/09/9.bqn17
1 files changed, 17 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2022/09/9.bqn b/users/sterni/exercises/aoc/2022/09/9.bqn
new file mode 100644
index 000000000000..fff38b591311
--- /dev/null
+++ b/users/sterni/exercises/aoc/2022/09/9.bqn
@@ -0,0 +1,17 @@
+⟨SplitOn,ReadDec⟩ ← •Import "../../lib.bqn"
+i ← ReadDec⌾(1⊸⊑)¨ (<' ')⊸SplitOn¨ •FLines "input"
+
+UnitDelta ← (⊢÷(|+0⊸=))
+ExpandStep ← {
+  𝕊 "L"‿l: 𝕊 (-l)‿0;
+  𝕊 "R"‿r: 𝕊 r‿0;
+  𝕊 "U"‿u: 𝕊 0‿u;
+  𝕊 "D"‿d: 𝕊 0‿(-d);
+  𝕊 delta: ((⌈´|)⥊<∘UnitDelta) delta
+}
+
+Step ← {knots 𝕊 delta: {h 𝕊 t: (UnitDelta h-t) +⍟(1<⌈´|h-t) t}` (delta⊸+)⌾⊑ knots}
+Visited ← {+´0=⊒(¯1⊸⊑)¨(<𝕨⥊<0‿0) Step` ∾ExpandStep¨ 𝕩}
+
+•Out "day09.1: "∾•Fmt  2 Visited i
+•Out "day09.2: "∾•Fmt 10 Visited i