From fa17b27096c39a6e66824c54de5a93d300dd75a3 Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sat, 3 Dec 2022 08:39:34 +0100 Subject: [PATCH] =?UTF-8?q?day3=20bqn=20=F0=9F=A5=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aoc.bqn | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aoc.bqn b/aoc.bqn index 4df2e71..2f9325f 100644 --- a/aoc.bqn +++ b/aoc.bqn @@ -4,12 +4,20 @@ Sub ⇐ {a‿b𝕊𝕩:b↑a↓𝕩} # e Split xs: split xs on occurrences of e (default 0) Split ⇐ {(⊏ ∾ 1⊸↓¨∘(1⊸↓)) Sub⟜𝕩¨ (» ⋈¨ ⊢-») /𝕨=𝕩∾(𝕨⊣⟜0↩)} +# n Chunk xs: split into chunks of length n (the last one might be smaller) +Chunk ⇐ {(⌊𝕨÷˜↕≠𝕩)⊔𝕩} + Day1 ⇐ (⊑ ⋈ (+´3⊸↑))∘(∨+´¨)∘Split∘(•BQN⎊0¨)∘•FLines Day2 ⇐ { B ← ⊣ (A ← {1+𝕩+3×3|1+𝕩-𝕨}) {3|𝕨+𝕩-1} +´˘⍉ (A≍B)´∘{a‿s‿b:⟨a-'A',b-'X'⟩}˘ >•FLines 𝕩 } -•Show Day2 ⊑•args -# day 3 maybe later +Day3 ⇐ { + Prio ← ⊢ - ⊑⟜"`&"∘(≤⟜'Z') + A ← +´∘∾ {(Prio¨×∊⟜𝕩)𝕨}○⍷´∘(<˘ 2‿∘⊸⥊)¨ + B ← +´∘∾ {a‿b‿c:(Prio¨a)×b∧○(a⊸∊)c}¨∘(3⊸Chunk)∘(⍷¨) + (A⋈B) •FLines 𝕩 +} +# •Show Day3 ⊑•args