Skip to content

Instantly share code, notes, and snippets.

@ljos
Last active December 3, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljos/33315829e1bc70b208d47e49d1c30133 to your computer and use it in GitHub Desktop.
Save ljos/33315829e1bc70b208d47e49d1c30133 to your computer and use it in GitHub Desktop.
adventofcode2021.bqn
p ← •BQN ¨ •file.Lines ⊑ •args
T1 ← +´1↓»⊸<
T2 ← +´˘3↕⊢
•Show T1 p
•Show T1∘T2 p
val ← ⊐⟜' '⊸(↑⋈1↓↓)¨•Flines "ex-1.txt"
mov ← "forward"‿"down"‿"up"⊐(0⊑¨val)
amt ← •BQN¨1⊑¨val
•Show (×´+´) amt × mov ⊏ ⟨1‿0, 0‿1, 0‿¯1⟩
F ← +´0⊑¨⊢
D ← +´(1⊑¨⊢)×(+`2⊑¨⊢)
•Show (F×D) amt × mov ⊏ ⟨1‿1‿0, 0‿0‿1, 0‿0‿¯1⟩
val ← ∾˘'1'=¨ •Flines "problem-01.txt"
Len ← {1⊣´≢𝕩}
Base2 ← +⟜(2⊸×)´∘⌽
n ← Base2 ((Len val)÷2) < +´<˘val
m ← Base2 ((Len val)÷2) > +´<˘val
•Show n × m
OGR ← ⥊∘{x←𝕨⊑˘𝕩 ⋄ i←(0.5≤(+´x÷(Len 𝕩))) ⋄ (𝕨+1) {1<(Len 𝕩)}◶⊢‿𝕊 ((i⊑(⊔x))⊏𝕩)}
CSR ← ⥊∘{x←𝕨⊑˘𝕩 ⋄ i←(0.5>(+´x÷(Len 𝕩))) ⋄ (𝕨+1) {1<(Len 𝕩)}◶⊢‿𝕊 ((i⊑(⊔x))⊏𝕩)}
•Show (Base2 ∘ OGR val) × (Base2 ∘ CSR val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment