4. How the Tables have Turned
Note: In this problem, you’re asked to enter an APL expression (some APL code), including arguments (data given to APL symbols). Your code will be tested by the APL Challenge system to check whether it gives the correct answer and uses the methods described below.
Symbols that are used to change data are called functions. For example, APL uses the function + (Plus) for addition.
An APL function takes the answer of all the code to its right as its right argument. For example, 2×3+4 gives 14, rather than the 10 that you might expect. This is because the × takes the answer of 3+4 as its right argument.
⍴ (Rho, a Greek letter) is called Reshape (Rho is like an r for reshape). It can take a list of two numbers on the left and any data on the right. The two numbers state how many rows and columns the data on the right should be reshaped into.
For example, to get a table with 3 rows and 5 columns, filled with 7 9 4, you'd write 3 5 ⍴ 7 9 4. It'd look like this:
7 9 4 7 9
4 7 9 4 7
9 4 7 9 4
The numbers are reused as needed to fill the rows and columns, first filling the top row, then the next one, and so on.
Using Reshape (⍴) and Iota (⍳ from problem 1), create the following table of numbers:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24