2022-12-02 01:19:46 -05:00
|
|
|
|
# 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)
|
2022-12-03 05:24:23 -05:00
|
|
|
|
Split ⇐ {(⊏ ∾ 1⊸↓¨∘(1⊸↓)) Sub⟜𝕩¨ (» ⋈¨ ⊢-») /w=𝕩∾(w←𝕨⊣0)}
|
2022-12-02 01:19:46 -05:00
|
|
|
|
|
2022-12-03 02:39:34 -05:00
|
|
|
|
# n Chunk xs: split into chunks of length n (the last one might be smaller)
|
|
|
|
|
Chunk ⇐ {(⌊𝕨÷˜↕≠𝕩)⊔𝕩}
|
|
|
|
|
|
2022-12-02 02:41:12 -05:00
|
|
|
|
Day1 ⇐ (⊑ ⋈ (+´3⊸↑))∘(∨+´¨)∘Split∘(•BQN⎊0¨)∘•FLines
|
2022-12-03 05:24:23 -05:00
|
|
|
|
# ⟨ 72602 207410 ⟩
|
2022-12-02 02:41:12 -05:00
|
|
|
|
|
|
|
|
|
Day2 ⇐ {
|
|
|
|
|
B ← ⊣ (A ← {1+𝕩+3×3|1+𝕩-𝕨}) {3|𝕨+𝕩-1}
|
2022-12-04 17:52:42 -05:00
|
|
|
|
+´ (A⋈B)´∘{"AX"-˜0‿2⊏𝕩}¨ •FLines 𝕩
|
2022-12-01 14:37:22 -05:00
|
|
|
|
}
|
2022-12-03 05:24:23 -05:00
|
|
|
|
# ⟨ 17189 13490 ⟩
|
2022-12-03 00:33:45 -05:00
|
|
|
|
|
2022-12-03 02:39:34 -05:00
|
|
|
|
Day3 ⇐ {
|
2022-12-04 17:52:42 -05:00
|
|
|
|
Prio ← ⊢ - ≤⟜'Z'◶"`&"
|
2022-12-03 02:39:34 -05:00
|
|
|
|
A ← +´∘∾ {(Prio¨×∊⟜𝕩)𝕨}○⍷´∘(<˘ 2‿∘⊸⥊)¨
|
|
|
|
|
B ← +´∘∾ {a‿b‿c:(Prio¨a)×b∧○(a⊸∊)c}¨∘(3⊸Chunk)∘(⍷¨)
|
|
|
|
|
(A⋈B) •FLines 𝕩
|
|
|
|
|
}
|
2022-12-03 05:24:23 -05:00
|
|
|
|
# ⟨ 7683 2488 ⟩
|
2022-12-04 04:03:30 -05:00
|
|
|
|
|
|
|
|
|
Day4 ⇐ {
|
2022-12-04 17:52:42 -05:00
|
|
|
|
Line ← •BQN '‿'⍟(⊑∊⟜"-,")¨ # hehe
|
|
|
|
|
F ← {∨´∧´˘≥´⎉1(3⥊2)⥊𝕩⊏˜𝕨-'a'}
|
2022-12-04 04:51:21 -05:00
|
|
|
|
A ← "cabddbac"⊸F, B ← "cabcacda"⊸F
|
2022-12-04 17:52:42 -05:00
|
|
|
|
+´ (A⋈B)∘Line¨ •FLines 𝕩
|
2022-12-04 04:03:30 -05:00
|
|
|
|
}
|
|
|
|
|
# ⟨ 536 845 ⟩
|
2022-12-05 07:24:35 -05:00
|
|
|
|
|
|
|
|
|
Day5 ⇐ {
|
|
|
|
|
inp ← •FLines 𝕩
|
|
|
|
|
Start ← {(𝕨⊸=⊑⎊0)¨⊸/ 𝕩}
|
2022-12-06 00:35:24 -05:00
|
|
|
|
stks ← ' '⊸≠⊸/¨ <˘⍉> (1⊸⊑¨ 4⊸Chunk)¨ '[' Start inp
|
2022-12-05 07:24:35 -05:00
|
|
|
|
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" ⟩
|
|
|
|
|
|
2022-12-06 00:35:24 -05:00
|
|
|
|
Day6 ⇐ {{𝕨+ ⊑/ ≡⟜⍷¨ <˘ 𝕨↕𝕩}⟜(⊑•FLines 𝕩)¨ 4‿14}
|
|
|
|
|
# ⟨ 1929 3298 ⟩
|
|
|
|
|
|
|
|
|
|
# •Show Day6 ⊑•args
|