de4004a8ea
Retrieves all diagonals of a two dimensional array (which have differing lengths). Useful to solve e.g. Project Euler problem 11 (<https://projecteuler.net/problem=11>). Change-Id: I853bc6eaaf869326d84d8e789fee9995f5a332d8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12897 Autosubmit: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
21 lines
658 B
BQN
21 lines
658 B
BQN
IsAsciiNum ⇐ ('0'⊸≤∧≤⟜'9')
|
||
IsAlpha ⇐ (('a'⊸≤∧≤⟜'z')∨('A'⊸≤∧≤⟜'Z'))
|
||
|
||
# based on leah2's function
|
||
ReadInt ⇐ {
|
||
𝕨 𝕊 𝕩: '-'=⊑𝕩? -𝕨 𝕊 1↓𝕩;
|
||
𝕨 𝕊 𝕩: (𝕨⊸×+⊣)´∘⌽-⟜'0'𝕩
|
||
}
|
||
ReadDec ⇐ 10⊸ReadInt
|
||
|
||
SplitOn ⇐ ((⊢ (-1˙)⍟⊣¨ +`∘(1⊸»<⊢))∘(≡¨)⊔⊢)
|
||
SplitAt ← ((⊣≤↕∘≠∘⊢)⊔⊢)
|
||
|
||
_fix ⇐ {𝕩 𝕊∘⊢⍟≢ 𝔽 𝕩}
|
||
|
||
ImportBqnLibs ⇐ {•Import 𝕩∾˜"/"∾˜¯1↓1⊑•SH "printenv"‿"BQNLIBS"}
|
||
|
||
Xor ⇐ (¬⊸∧∨∧⟜¬)
|
||
|
||
# To get all Diagonals (⊢∾○Diagonals⌽)
|
||
Diagonals ⇐ {(0‿0⊸⍉ ↓⟜𝕩)¨ (↕≠𝕩)}
|