# a‿b Sub x: the b-length subarray starting at a Sub ⇐ {a‿b𝕊𝕩:b↑a↓𝕩} # e Split xs: split xs on occurrences of e (default 0) Split ⇐ {(⊏ ∾ 1⊸↓¨∘(1⊸↓)) Sub⟜𝕩¨ (» ⋈¨ ⊢-») /w=𝕩∾(w←𝕨⊣0)} # n Chunk xs: split into chunks of length n (the last one might be smaller) Chunk ⇐ {(⌊𝕨÷˜↕≠𝕩)⊔𝕩} Day1 ⇐ (⊑ ⋈ (+´3⊸↑))∘(∨+´¨)∘Split∘(•BQN⎊0¨)∘•FLines # ⟨ 72602 207410 ⟩ Day2 ⇐ { B ← ⊣ (A ← {1+𝕩+3×3|1+𝕩-𝕨}) {3|𝕨+𝕩-1} +´ (A⋈B)´∘{"AX"-˜0‿2⊏𝕩}¨ •FLines 𝕩 } # ⟨ 17189 13490 ⟩ Day3 ⇐ { Prio ← ⊢ - ≤⟜'Z'◶"`&" A ← +´∘∾ {(Prio¨×∊⟜𝕩)𝕨}○⍷´∘(<˘ 2‿∘⊸⥊)¨ B ← +´∘∾ {a‿b‿c:(Prio¨a)×b∧○(a⊸∊)c}¨∘(3⊸Chunk)∘(⍷¨) (A⋈B) •FLines 𝕩 } # ⟨ 7683 2488 ⟩ Day4 ⇐ { Line ← •BQN '‿'⍟(⊑∊⟜"-,")¨ # hehe F ← {∨´∧´˘≥´⎉1(3⥊2)⥊𝕩⊏˜𝕨-'a'} A ← "cabddbac"⊸F, B ← "cabcacda"⊸F +´ (A⋈B)∘Line¨ •FLines 𝕩 } # ⟨ 536 845 ⟩ Day5 ⇐ { inp ← •FLines 𝕩 Start ← {(𝕨⊸=⊑⎊0)¨⊸/ 𝕩} stks ← ' '⊸≠⊸/¨ <˘⍉> (1⊸⊑¨ 4⊸Chunk)¨ '[' Start inp todo ← •BQN⚇1 (1‿3‿5⊸⊏ ' '⊸Split)¨ 'm' Start inp _Do1 ← { n‿s‿t ← 𝕩 - 0‿1‿1 l‿r ← n (↑⋈↓) s⊑𝕨 (𝔽 l)⊸∾⌾(t⊸⊑) r⌾(s⊸⊑) 𝕨 } _Do ← {⊑¨ 𝕨𝔽_Do1˜´⌽𝕩}, A ← ⌽_Do, B ← ⊢_Do stks (A⋈B) todo } # ⟨ "QNNTGTPFN" "GGNPJBTTR" ⟩ Day6 ⇐ {{𝕨+ ⊑/ ≡⟜⍷˘ 𝕨↕𝕩}⟜(•FChars 𝕩)¨ 4‿14} # ⟨ 1929 3298 ⟩ Day8 ⇐ { _rots ← {F‿x←𝔽‿𝕩, >{F⌾𝕏x}¨⟨⊢,⍉,⌽˘,⍉⌽⟩} A ← {+´⥊ ∨˝ ∧´∘(⊑>1⊸↓)¨ 𝕩} B ← {⌈´⥊ ×˝ {1⊑⎊(1-˜≠𝕩) (/⊢≥⊑) 𝕩}¨ 𝕩} (A⋈B) (¯1↓↓)˘_rots '0'-˜ >•FLines 𝕩 } # ⟨ 1843 180000 ⟩ Day10 ⇐ { Line ← 0∾ ·•BQN⎊⟨⟩ 5↓⊢ A ← (+´ 19⊸⊏∘⍉) (⊢×1+↕∘≠⌾⥊) B ← ⊏⟜" █" (1≥⟜|-)⟜(↕≠)˘ (A⋈B) ∘‿40⥊ +` 1»∾Line¨ •FLines 𝕩 } # ⟨ 13060 "FJUBULRZ" ⟩ # (but the string is a big banner) Day18 ⇐ { # part 1 only :[ grid ← (↕∘> 1+⌈˝)⊸∊ •BQN¨ '‿'⍟(=⟜',')⚇0 •FLines 𝕩 touch ← +´⥊ «‿» {∧⟜(𝕎⎉𝕩) grid}⌜ 1+↕3 +´⥊ (6×grid)-touch } # 3470