Post History
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) ...
Question
code-golf
#2: Post edited
Evaluation order of an APL n-train
- ## Description
- APL [trains](https://aplwiki.com/wiki/Tacit_programming#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 3 2 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
- ```
- ## Description
- APL [trains](https://aplwiki.com/wiki/Tacit_programming#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
- ```
#1: Initial revision
Evaluation order of an APL n-train
## Description APL [trains](https://aplwiki.com/wiki/Tacit_programming#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 3 2 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 ```