f f r 2
2
r
r d
f s t f
d
dip f s t
f
t
dot f
dot
s
s dip
f
dab
Try it online!
Explanation:
f
is an alias for dab
(tail).
s
is subtraction, as explained on the wiki: (x, y) → (0, y−x) when x ≤ y.
t
maps (a, b, c…) to (b+c+…, a+b+c+…).
f s t
maps (a, b, c…) to a. This is our “head” function.
d
dips only the head of its argument: (a, b, c…) → (|a−1|, b, c…)
r
is the main repetition logic. We map (a, b) to (*r(|a−1|, b), b).
For example, r(4, 7) will evaluate as
r(4, 7)
= r(3, 7), 7
= r(2, 7), 7, 7
= r(1, 7), 7, 7, 7
= r(0, 7), 7, 7, 7, 7
→ This would call r(1, 7), but (1, 7) ≥ (0, 7), so surrender!
= 0, 7, 7, 7, 7, 7.
Finally, we define 2
, which maps n → (n, n), and define main
as f f r 2
, computing r(n, n) and chopping off the first two elements.
built-in
. \$\endgroup\$*
operator ok? What's an example of a built-in that isn't ok? \$\endgroup\$