-
Notifications
You must be signed in to change notification settings - Fork 60
/
r0.bqn
50 lines (44 loc) · 1.85 KB
/
r0.bqn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# BQN runtime part 0. Requires:
# Fill _fillBy_
# +-×⌊=≤≢⥊⊑↕⌜⊘
# Provides:
# ⌊⌈|<>≠≥⊢⊣∾⋈↑↓⊏˙˜¨´∘○⊸⟜◶⍟
# ^^^^^^^ ^^^^^ ^^ ^^ are limited, suitable for r1
⊢ ← {𝕩}
⊣ ← {𝕩}⊘{𝕨}
˙ ← {𝕩⋄𝕗}
˜ ← {𝕩𝔽𝕨⊣𝕩}
∘ ← {𝔽𝕨𝔾𝕩}
○ ← {(𝔾𝕨)𝔽𝔾𝕩}
⊸ ← {(𝔽𝕨⊣𝕩)𝔾𝕩}
⟜ ← {(𝕨⊣𝕩)𝔽𝔾𝕩}
◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # LIMITED to number left operand result
⍟ ← {𝕨((𝕨𝔾𝕩)⊑⊢‿𝕗){𝔽}𝕩} # LIMITED to boolean right operand result
Box ← {𝕩Fill⟨⟩⥊⟨𝕩⟩}
# LIMITED to numeric arguments for arithmetic cases
≥ ← ≤˜
< ← Box ⊘ (1-≥)
> ← (1-≤)
⌊ ↩ ⌊ ⊘ (⊣-≥×-)
⌈ ← -∘⌊∘- ⊘ (⊣-≤×-)
| ← 0⊸≤◶-‿⊢
≠ ← (0<=)◶⟨1⋄0⊑≢⟩ # LIMITED to monadic case
⋈ ← {⟨𝕩⟩} ⊘ {⟨𝕨,𝕩⟩} # LIMITED by not having a result fill
∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two list arguments
↑ ← {⊑⟜𝕩⌜↕𝕨} # LIMITED to number 𝕨 and list 𝕩
↓ ← {(𝕨⊸+⊑𝕩˙)⌜↕(≠𝕩)-𝕨} # LIMITED to number 𝕨 and list 𝕩
¨ ← { d←⥊𝕩⋄(≢𝕩)⥊(⊑⟜(⥊𝕨)𝔽⊑⟜d)⌜↕≠d } # LIMITED to equal-shape arrays
_fold0←{
l←≠𝕩 ⋄ F←𝔽
r←𝕨 {l↩l-1⋄l⊑𝕩}⊘⊣ 𝕩
({r↩𝕩 F r}(l-1)⊸-⊑𝕩˙)⌜↕l
r
}
´ ← _fold0 # LIMITED to nonempty list 𝕩, or 𝕨 and list 𝕩
GetCells←(1==∘⊢)◶{
c←1×´s←1↓≢𝕩
(c⊸×⌜𝕨)(+⊑(⥊𝕩)˙)⌜s⥊↕c
}‿{
⊑⟜𝕩⌜𝕨
} _fillBy_ ⊢
⊏ ← GetCells # LIMITED to depth-1 natural number left argument