Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

81%
+7 −0
Challenges 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) ...

7 answers  ·  posted 3y ago by rak1507‭  ·  last activity 3y ago by Shaggy‭

Question code-golf
#2: Post edited by user avatar Adám‭ · 2021-06-07T21:32:11Z (over 3 years ago)
important typo
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 by user avatar rak1507‭ · 2021-06-07T21:08:03Z (over 3 years ago)
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
```