about summary refs log tree commit diff
path: root/day14.bqn
blob: a54b14c5dc5dc1ae1700754d79e40c08fa694b64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
str←•Import"bqn-libs/strings.bqn"
template‿rules ← (⊑⋈2⊸↓) str.lf str.Split ¯1↓ •FChars"day14"
rules ↩ >(" -> " ⊸ str.Split)¨ rules

pairs ← ⊏˘rules
letters ← ⊑¨pairs

f ← +´˘ pairs ≡⌜ <˘ 2↕template
t ← ¬ (¯1 ↑ template) ⊒ letters

m ← ((<˘⊑¨rules) ≡⌜ pairs) + ((<˘⊑∘⌽¨⌽˘rules) ≡⌜ pairs)

•Show (⌈´-⌊´) +´¨ (⊐ letters) ⊔ t + m⊸(+˝∘×)⍟10 f
•Show (⌈´-⌊´) +´¨ (⊐ letters) ⊔ t + m⊸(+˝∘×)⍟40 f