aoc2021-bqn/aoc.bqn

139 lines
4.1 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ReadInt (+ (10×))´ (-'0')
IntFile ReadInt¨ •FLines
aoc1 {
A +´ (>(»)) IntFile
B +´ (>(»)) (+´˘) (3) IntFile
}
################################################################################
Split ((+`׬) - )= # from bqn crates lmao
Words ((0)¨/) (' 'Split)
CSV ','Split
CSVInt ReadInt¨ CSV
aoc2 {
Move1 { "forward" 𝕊 x: x0; "down" 𝕊 y: 0y; "up" 𝕊 y: 0,-y }
Move Move1ReadInt´ Words
MoveFile Move¨ •FLines
DoMoveB {dxda 𝕊 xya : x+dx, y+(dx×a), a+da}
A ×´ +´ MoveFile
B ×´ (2) (000(DoMoveB´)) MoveFile
}
################################################################################
FromBin +´ 2 ×
BitFile (-'0') > •FLines
aoc3 {
Most (() )
Gamma Most˘ BitFile
A ¬(×FromBin) Gamma
B {"nah"!0, 𝕩}
}
################################################################################
aoc4 {
BingoFile {
lines •FLines 𝕩
picks CSVInt lines
boards ReadInt¨ > Words¨ 1˘ 6 1lines
states boards <(0¨`) picks
}
Win ´ ((´ 0)˘)()
Score +´
A {
picksstates BingoFile 𝕩
0/ +´¨ picks × (Score × Win)˘¨ states
}
B {
picksstates BingoFile 𝕩
pickcurprev ((´ Win˘)¨ states) / (picks ¨ states ¨ »states)
pick × Score (¬Win˘ prev) / cur
}
}
################################################################################
aoc5 {
VentFile ReadInt¨(CSV¨ 02)Words¨ •FLines
To {𝕨𝕩? 𝕩; (𝕨>𝕩) (𝕨𝕩) (1+𝕨𝕩)}
DrawLine {x1y1x2y2: (x1 To x2) ¨ (y1 To y2)}
Orth {´ =´ <˘ 2 𝕩}
Danger {1 / DrawLine¨ 𝕩}
A Danger (Orth¨/ VentFile), B Danger VentFile
}
################################################################################
aoc6 {
FishFile 9 / CSVInt •FLines
Step ( × (/68)˙) + «
Fishies {+´ Step𝕨 FishFile 𝕩}
A 80Fishies, B 256Fishies
}
################################################################################
aoc7 {
CrabFile CSVInt •FLines
Range {l + (´𝕩)¬(l´𝕩)}
FuelA +´ | -
FuelB +´(÷2)(×+1)| -
_Go {´ ps𝔽¨ Range psCrabFile 𝕩}
A FuelA _Go, B FuelB _Go
}
################################################################################
aoc8 {AB{"maybe later"!0, 𝕩}}
################################################################################
aoc9 {
SmokeFile > -'0' •FLines
Adj {<1 > «˘𝕩, »˘𝕩, «˘𝕩, »˘𝕩}
Lowest ´¨ <Adj
Risk 1+ × Lowest
A +´ Risk SmokeFile
B {"nah"!0, 𝕩}
}
################################################################################
At {1 ( 𝕩˙)¨/ 𝕨} # use ⎊ for default
aoc10 {
BadScore1 ')'3,']'57,'}'1197,'>'25137At
BadScore {'!'c: BadScore1 c; 0}
pairs Words "() [] {} <>"
Step {
'!' @ 𝕩? 𝕩;
𝕨 = pairs At@ 𝕩? 1𝕩;
𝕨 ¨pairs? 𝕨𝕩;
'!'𝕨
}
Find ""(Step´)
GoodScore1 '('1,'['2,'{'3,'<'4At
GoodScore {'!' 𝕩? 0 ((GoodScore1 ) + (5× ))´ 𝕩; 0}
Middle ((÷2) ) (0¨/)
A +´ BadScoreFind¨ •FLines
B Middle GoodScoreFind¨ •FLines
}