1: 1-2-3
2: Areas
3: Selection
4: Tables
5: Backwards
6: Palindrome
7: Palindromes
8: Heat
9: Babushka
10: X
Your Answers
LocalStorage is disabled or you are using an old browser. Please register (and log in) to have your solutions saved.
APL Logo

Welcome to the APL Challenge!

The deadline for the current round (2024.4) is Friday 31 January 2025 at 09:00 UTC.

APL is a programming language that will change the way you think about solving problems. You don’t need to know any APL or programming at all to participate in this challenge; the question texts will teach you everything you need to know to progress. To do this, we have kept what we teach very simple, even though APL is slightly more complicated than what we describe.

There are four rounds of the APL Challenge each year. You don’t need to participate in an earlier round to participate in the current one. Each round has ten problems and runs for three months, after which Dyalog Ltd awards three USD 100 prizes. You don’t have to answer every question, but your chance of winning increases as you answer more questions. A list of winners of previous rounds is available on the Dyalog website.

If you’re interested but don’t want to participate in this round, please register anyway (using the button at the top) so that we can notify you of updates and tell you about future rounds. You can ask us to stop sending you emails at any time.

Let’s get started…

Use TryAPL to experiment and find your answer. You can write APL symbols by clicking on them in the language bar above the area where you write APL code.

Although you can begin without registering – most browsers will store your answers until you register – you must be registered and logged in to submit (send in) your answers. When you’re happy with your answer, hit  Submit. The system will only allow you to submit correct answers.

Several problems include some data you need. You should be able to copy text that is written with code letters like this by clicking on it, but note that not all browsers allow this.

Prizes

Anyone can win a prize except Dyalog employees and associates. We reserve the right to choose the winners at our sole discretion and will not enter into conversation about our choices.

All prizes are denominated in U.S. dollars, but can be awarded in U.S. dollars (USD), pounds sterling (GBP) or euros (EUR) by electronic transfer to a bank account or a PayPal account. No other forms of payment will be made.

If you are selected as a winner but are unable or unwilling to accept the prize, you cannot transfer the prize or designate someone else as the winner. Prizes must be claimed within three weeks of being notified or you forfeit the right to that prize.

If you accept a prize, you will be solely responsible for all applicable taxes related to accepting that prize.

Sponsors

Detailed rules

Conditions

All participants must submit to these rules.

Multiple registrations to a single round are not allowed.

Participants must provide truthful and accurate information regarding contact and personal information.

Participants must not publish their solutions prior to the end of the challenge round. Doing so will be considered grounds for disqualification from the challenge round.

Only entries that are received by the deadline are eligible. We cannot accept responsibility for entries that are lost, delayed or damaged. Proof of sending an online entry is not proof that we received it.

Entries not submitted in accordance with these terms and all other rules and directions (at the sole discretion of Dyalog Ltd) will be excluded from the challenge round.

Your submission and its contents can be used at the discretion of Dyalog Ltd.

Collaboration

Participants must ensure that all solutions that they submit are produced and owned by them.

You can collaborate with others in learning APL and solving the problems, but each submission must be made by a single person and only that person will be eligible for a prize. Each collaborator can submit an entry.

Frequently Asked Questions (FAQ)

In APL, how do I…?

In fairness to all, we cannot provide answers to challenge-specific questions. Instead, have a look at the Getting Started guide.

Why is my correct answer not accepted?

The purpose of the APL Challenge is to teach specific parts of APL, so we require solutions that use the techniques we teach. Most problems can be solved in many ways, and the techniques we teach here do not necessarily lead to the best code. If you want to explore alternative answers, then you can use TryAPL to do so.

Why can I not change my answer?

When you test or submit a correct answer, we lock it down for you, so it isn’t accidentally overwritten with an incorrect answer. All correct answers are equally eligible for winning. If you want to explore alternative answers, then you can use TryAPL to do so.

Does the possibility of winning prize money classify as commercial use of Dyalog?

No.

What do I do if there is a problem with this website or I have a question about a problem?

Please report any problems or direct any questions to challenge@dyalog.com.

I did not receive an email with a code when registering. What should I do?

Click Register again and wait for 5–10 minutes. Make sure you check your spam folder. If the code still doesn't come through, then please report the problem to challenge@dyalog.com.

Data protection and cookies

We use cookies to keep you logged in and to retain your solutions. By using this site, you agree to this.

We only collect the data necessary for the competition to run, and will use any personal information submitted in accordance with Dyalog Ltd's Privacy Policy.

At any time after you have registered and are logged in, you can erase all data that is stored about you as part of the competition by clicking the user button email@domain.com in the top right corner and selecting Erase account and data.

Consent to usage of information

By participating in the challenge, you consent to the use by Dyalog Ltd of all text and code that you submit, for any purpose, in any media, for an unlimited period, without remuneration. We have the right to publish, display, reproduce, adapt, promote or otherwise use entries in any way we deem fit. You warrant that you are legally entitled to grant these rights to us and agree to indemnify us in the event that we suffer any loss as a result of false information you provide.

By participating in the challenge, you agree that if you win and subsequently participate in any promotional activities or material, you will do so without additional payment or permission.

Disclaimers

We are not liable for any damage, loss or disappointment suffered by you for taking part or not being able to take part in this competition.

In the event of unforeseen circumstances, we may alter, amend or cancel the competition without prior notice.

We reserve the right to change these terms at any time.

These terms are governed by the Laws of England and Wales and all disputes subject to the jurisdiction of the courts of England and Wales.

Technology

This site was constructed with, and runs on,

MiServer, a free, open-source web server implemented in Dyalog APL. It enables the APL user to build sophisticated websites using the power of APL and with minimal knowledge of web technologies like HTML, JavaScript, and CSS.

To safely verify submissions, we use

Safe Execute for Dyalog APL, a tool developed by Adám Brudzewsky that validates APL expressions as non-destructive, covering built-ins if necessary, and executes them in a sandbox environment.

Contact

If you have feedback, or would like to ask a question that is not already answered here, please e-mail challenge@dyalog.com.

image/svg+xml
APL Challenge 2024.4

Note: 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 that it gives the correct answer and uses the methods described below.


1: Easy as 1-2-3

It is easy to count in APL. Just write the symbol (iota, a Greek letter), to the left of a number; this will give you all the whole numbers from 1 to the number you wrote. (Iota is like an i for integers, which means whole numbers.) For example. ⍳ 10 gives 1 2 3 4 5 6 7 8 9 10


Write some APL code that uses to get the numbers from 1 to 42. The result should be 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

Answer:Answer:

Note: 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 that it gives the correct answer and uses the methods described below.


2: Rectangle Areas

In APL, multiplication uses the symbol × (times). It works as you’d expect. However, in APL all basic mathematical symbols can work on multiple numbers at once. For example, 5 2 3 × 2 4 3 gives 10 8 9 because:

  • 5 × 2 is 10
  • 2 × 4 is 8
  • 3 × 3 is 9

Write some APL code that uses a single × to calculate the area of three rectangles. The first has sides of length 3 and 2, the second has sides of length 1 and 7, and the third has sides of length 4 and 2. The result should be 6 7 8

Answer:Answer:

Note: 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 that it gives the correct answer and uses the methods described below.


3: Selection

In APL, text must appear between single quotes ('). For example, 'ABC' will give a result that looks like ABC.

You can select specific letters from a text by putting square brackets ( [] ) to the right of the text. Inside the square brackets, you put numbers that say which letters you want to get from the text. For example, 'ABCDE'[1] gives you the letter A because that’s the 1st letter of 'ABCDE'. Similarly, 'ABCDE'[5 2 2] gives you EBB, because:

  • The 5th letter of 'ABCDE' is E
  • The 2nd letter of 'ABCDE' is B
  • The 2nd letter of 'ABCDE' is B

Write some APL code using square brackets that transforms 'DYALOG APL' into 'GO POLLY'

Answer:Answer:

Note: In this problem, you’re asked to write 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 that it gives the correct answer and uses the methods described below.


4: How the Tables have Turned

An APL symbol 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
Answer:Answer:

Note: In this problem, you’re asked to write 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 that it gives the correct answer and uses the methods described below.


5: All Backwards

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 the previous problem that takes the answer of 2 3 ⍴ 'SAWNET' as its right argument. Therefore, the result is:

WAS
TEN

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

Some APL symbols 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 Reverse () and Each (¨), turn 'mood' 'net' 'pop' into:

┌───┬───┬────┐
│pop│ten│doom│
└───┴───┴────┘

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

Answer:Answer:

Note: In this problem, you’re asked to write 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 that it gives the correct answer and uses the methods described below.


6: Palindrome

In APL, yes/no questions are answered with 1 for yes and 0 for no.

The symbol is Match. It reports whether whatever is on its left matches whatever is on its right. For example, 'You' ≡ 'You' gives 1. However, 'I' 'Like' 'You' ≡ 'I' 'Love' 'You' gives 0, because we don’t look at each word separately, only at the whole list of texts.

Remembering ¨ from problem 5, you can see that 'I' 'Like' 'You' ≡¨ 'I' 'Love' 'You' gives 1 0 1, because:

  • 1: yes, 'I' matches 'I'
  • 0: no, 'Like' does not match 'Love'
  • 1: yes, 'You' matches 'You'

Using Match () and Reverse ( from problem 5), check whether 'APL' is a palindrome (a word that stays the same when read backwards). Hint: It is not, so the answer should be 0.

Answer:Answer:

Note: In this problem, you’re asked to enter your own APL function, without giving it any arguments. Your code will be checked by the APL Challenge system using several tests to see whether it is correct.


7: More Palindromes

You can create your own function by putting an expression (for example, ⍳10) in curly brackets (for example, {⍳10}). Within the inner expression (in our example, ⍳10), (the Greek letter omega) stands for the argument to the right of the closing curly bracket ( } ). (Omega is the right-most letter of the Greek alphabet.)

For example, a function that multiplies its argument by two could be written {2×⍵}, so {2×⍵}5 gives 10.

Remember from problem 4 that the right argument of each function is the result of all the code to its right. This means that a function that subtracts one from its argument and then multiplies it by two, could be written {2×⍵-1}.


Using what you learnt in problem 6, write a function that checks whether its argument is a palindrome (a word that stays the same when read backwards). For example:

      {answer} 'racecar'
1

      {answer} 'medium'
0

      {answer} 'civic'
1
Answer:Answer:

In this problem, you’re asked to enter your own APL function, without giving it any arguments. Your function will be checked by the APL Challenge system using several tests to see whether it is correct.


8: Turning up the Heat

In problem 7, you saw how to write a function that takes a right argument using . If you want to create a function that also takes a left argument, use (alpha; the left-most letter of the Greek alphabet). For example, a function that sums its left and right arguments and then multiplies by two could be written {2×⍺+⍵}.

In problem 5, you saw how we can create lists simply by putting elements next to each other. This also works for argument names that are separated by spaces:

      {⍵ ⍵ ⍵} 4
4 4 4

      {⍵ ⍵ ⍵} 'd'
ddd

We call this Stranding, like a strand of thread.

Another way to join things is by using , (Catenate but usually just said aloud as Comma). For example, 2 , 3 gives 2 3. This is a normal function, so it follows the rules you learnt in problem 4. Catenate and Stranding behave differently when at least one element is a list. In such a case, Catenate joins the two arguments into a single list:

      'Hot' , 'Dog'
HotDog

In contrast, stranding of two things always creates a two-element list:

      'Hot' 'Dog'
┌───┬───┐
│Hot│Dog│
└───┴───┘

Write a function using Stranding, Reshape ( from problem 4), and Catenate (,) that takes a letter as its left argument and a size as its right argument, then produces a square table of the given size. The table should be made entirely of plus symbols (+), replaced by the given letter marking the diagonal from the top left to the bottom right:

      'o' {answer} 3
o++
+o+
++o

      'Q' {answer} 4
Q+++
+Q++
++Q+
+++Q
Answer:Answer:

In this problem, you’re asked to enter your own APL function, without giving it any arguments. Your function will be checked by the APL Challenge system using several tests to see whether it is correct.


9: Babushka

In problem 7 and problem 8, you saw that you could write your own function using APL symbols. You can also write functions that contain other functions that you have written. For example, a function that, given a letter, reshapes it into 3 copies, and then reshapes each copy into a 2-by-4 table, could be written like this:

      { {2 4⍴⍵}¨ 3⍴⍵} 'a'
┌────┬────┬────┐
│aaaa│aaaa│aaaa│
│aaaa│aaaa│aaaa│
└────┴────┴────┘

In problem 5, you saw how the Each (¨) operator can be used with functions that take a single argument (which is then on the right). It can also be used with a function that takes both a right argument and a left argument. In this case, it pairs up elements from the left with elements from the right:

      1 2 3 ⍴¨ 'abc'
┌─┬──┬───┐
│a│bb│ccc│
└─┴──┴───┘

Using the way of selection you learnt in problem 3, write a function that takes a list of numbers on the left and a list of words on the right. It must then use the first number on the left to select a letter from the first word on the right, use the second number to select a letter from the second word, and so on:

      3 2 1 {answer} 'here' 'be' 'dragons'
red

      3 3 1 5 {answer} 'just' 'eat' 'apple' 'today'
stay
Answer:Answer:

In this problem, you’re asked to enter your own APL function without giving it any arguments. Your function will be checked by the APL Challenge system using several tests to see whether it is correct.


10: X Marks the Spot


Using everything that you’ve learnt so far, write a function that takes a size as right argument and draws a large X of that size. Use backslash symbols (\) and slash symbols (/) for the diagonals:

      {answer} 4
\  /
 \/ 
 /\ 
/  \

When your function is given an odd number as argument, then the diagonals meet in a single letter. Put an X there:

      {answer} 5
\   /
 \ / 
  X  
 / \ 
/   \
Answer:Answer:

Your Answers

You must be logged in to view submitted solutions!