Comments on Evaluation order of an APL n-train
Post
Evaluation order of an APL n-train
Description
APL trains are a series of functions, that get applied to an argument in this way:
(f g) x = f g x
(f g h) x = (f x) g (h x)
(a b c d e f) x = (a (b c (d e f))) x = a (b x) c (d x) e (f x)
Trains evaluate from the right to the left, so in the last example, (f x) is evaluated, then (d x), then (d x) e (f x), then (b x), etc.
The final evaluation order there is FDEBCA, or using numbers instead, 6 4 5 2 3 1.
Challenge
Given a number n, output the evaluation order of a train with n functions. Your result can be 0 indexed or 1 indexed.
Examples
Here are the first 10 outputs starting from n=1 (1 indexed)
1 (0 if 0 indexed)
2 1 (1 0 if 0 indexed)
3 1 2
4 2 3 1
5 3 4 1 2
6 4 5 2 3 1
7 5 6 3 4 1 2
8 6 7 4 5 2 3 1
9 7 8 5 6 3 4 1 2
10 8 9 6 7 4 5 2 3 1
BQN, 8 bytesSBCS ``` ⍒↕+2| …
3y ago
[Jelly], 8 bytes ṖUs2Uṭ …
3y ago
[Jelly], 5 bytes ḶHĊUỤ …
3y ago
[Haskell], 52 48 45 42 bytes …
3y ago
posix SH + [GNU sed], 43 bytes …
3y ago
Japt, 10 bytes o ÅÔò cÔ …
3y ago
[Husk], 8 bytes ηÖ↔mo⌈½ …
3y ago
1 comment thread