Skip to content

5. All Backwards

In this problem, you’re asked to enter some APL code, including an APL symbol and the data (text or numbers) given to it. Your code will be tested by the APL Challenge system to check whether it gives the correct answer and uses the methods described below.

So far, we’ve only used text (in single quotes, like 'DYALOG APL') and lists of numbers (with spaces between them, like 3 1 4 1 5 9). Both of these are simple lists; one is a list of letters (we count space as a letter), the other is a list of numbers (the spaces between numbers don’t count). APL can also handle lists in which every element is itself a list. For example, 'DYALOG' 'APL' is a list of two texts, that is, a list of two lists of letters.

⌽ is called Reverse. ⌽ 3 1 4 gives 4 1 3.

Now let’s look at a more complicated example: ⌽ 2 3 ⍴ 'SAWNET'. Remember from problem 4 that ⌽ takes the answer of 2 3 ⍴ 'SAWNET' as its right argument. Therefore, the result is:

WAS
TEN

The APL functions that you’ve met so far take either one data argument (on the right) or two data arguments (one on each side).

Some APL functions take a data argument on the right (just like a function), but on the left take a function instead of data. These symbols are called operators. An operator uses the given function with the given data in a specific way. ¨ (Each) is such an operator. It takes a list on its right, and a function on its left, and applies the function to each element of the list. For example, ⍳¨ 3 1 4 gives:

┌─────┬─┬───────┐
│1 2 3│1│1 2 3 4│
└─────┴─┴───────┘

Using ⌽ and ¨, turn 'MOOD' 'NET' 'POP' into:

┌───┬───┬────┐
│POP│TEN│DOOM│
└───┴───┴────┘

Note that both the list of words, and each word, have been reversed.