Skip to content

7. Mirror Mirror

Note: 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.

You can create your own function by putting an expression in curly brackets ( {} ). For example, the expression 2+3 becomes the function {2+3}. You can let the function take an argument by using (omega, the right-most letter of the Greek alphabet) in the expression; any is replaced by the argument to the right of the closing curly bracket ( } ).

For example, a function that multiplies its argument by two could be written {2×⍵}. Then:

  1. {2×⍵} 5 gives 10
  2. {2×⍵} 7 gives 14

When we write APL code and its result together, we often write the code above the result, with six spaces to the left of the code, so for example:

      2+2
4

Remember from problem 2 that a matrix can also be written with line breaks separating the rows:

[1  2  3  4
 5  6  7  8
 9 10 11 12]

For clarity, and since you won’t need to write any matrix into the Answer field, we will do this in the examples going forward.


Using what you learnt in problem 6, write a function that takes a matrix and gives 1 if the matrix is the same when mirrored and 0 if it changes when mirrored. For example:

      {answer} [1 2 1
                3 4 3
                5 5 5]
1

      {answer} [1 2 3
                1 2 3]
0

      {answer} [1 1
                0 0]
1

      {answer} [1 0
                1 1]
0