Home

Help
2023
2022
2021
2020
2019










2018
2017
2016
2015
2014
2013

1: Chunky Monkey

Write a function that, given a scalar or vector as the right argument and a positive (>0) integer chunk size n as the left argument, breaks the array’s items up into chunks of size n. If the number of elements in the array is not evenly divisible by n, then the last chunk will have fewer than n elements.

πŸ’‘ Hint: The partitioned enclose function XβŠ‚Y could be helpful for this problem.

Examples

      3 (your_function) ⍳9   ⍝ ]Box on is used to display the result
β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚1 2 3β”‚4 5 6β”‚7 8 9β”‚
β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
      3 (your_function) ⍳11
β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚1 2 3β”‚4 5 6β”‚7 8 9β”‚10 11β”‚
β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
      10 (your_function) 'Dyalog'
β”Œβ”€β”€β”€β”€β”€β”€β”
β”‚Dyalogβ”‚
β””β”€β”€β”€β”€β”€β”€β”˜
      2 (your_function) 'The' 'cat' 'in' 'the' 'hat' 'sat' 'pat'
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚β”Œβ”€β”€β”€β”¬β”€β”€β”€β”β”‚β”Œβ”€β”€β”¬β”€β”€β”€β”β”‚β”Œβ”€β”€β”€β”¬β”€β”€β”€β”β”‚β”Œβ”€β”€β”€β”β”‚
β”‚β”‚Theβ”‚catβ”‚β”‚β”‚inβ”‚theβ”‚β”‚β”‚hatβ”‚satβ”‚β”‚β”‚patβ”‚β”‚
β”‚β””β”€β”€β”€β”΄β”€β”€β”€β”˜β”‚β””β”€β”€β”΄β”€β”€β”€β”˜β”‚β””β”€β”€β”€β”΄β”€β”€β”€β”˜β”‚β””β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
      5 (your_function) ''   ⍝ result is 0-element vector of text vectors
      4 (your_function) 5
β”Œβ”€β”
β”‚5β”‚
β””β”€β”˜

2: Making the Grade

Score RangeLetter Grade
0–64F
65–69D
70–79C
80–89B
90–100A

Write a function that, given an array of integer test scores in the inclusive range 0–100, returns an identically-shaped array of the corresponding letter grades according to the table to the left.

πŸ’‘ Hint: You may want to investigate the interval index function X⍸Y.

Examples

      (your_function) 0 64 65 69 70 79 80 89 90 100
FFDDCCBBAA

      (your_function) ⍬  ⍝ returns an empty vector


      (your_function) 2 3⍴71 82 81 82 84 59
CBB
BBF

3: Grade Distribution

The school’s administrative department wants to publish some simple statistics. Given a non-empty character vector of single-letter grades, produce a 3-column, 5-row, alphabetically-sorted matrix of each grade, the number of occurrences of that grade, and the percentage (rounded to 1 decimal position) of the total number of occurrences of that grade. The table should have a row for each grade even if there are no occurrences of a grade.

Note: due to rounding the last column might not total 100%.

πŸ’‘ Hint: The key operator ⌸ could be useful for this problem.

Examples

      (your_function) 9 3 8 4 7/'DABFC'
A 3  9.7
B 8 25.8
C 7 22.6
D 9 29  
F 4 12.9

      (your_function) 20⍴'ABC'
A 7 35
B 7 35
C 6 30
D 0  0
F 0  0

      (your_function) ,'B'
A 0   0
B 1 100
C 0   0
D 0   0
F 0   0

4: Knight Moves

1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8
2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8
3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8
4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8
5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8
6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8
7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8
8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8

Consider a chess board as an 8Γ—8 matrix with square (1 1) in the upper left corner and square (8 8) in the lower right corner. For those not familiar with the game of chess, the knight, generally depicted as a horse (β™ž), can move 2 spaces right or left and then 1 space up or down, or 2 spaces up or down and then 1 space right or left. This means that a knight on square (5 4) can move to any of the indicated squares. Given a 2-element vector representing the current square for a knight, return a vector of 2-element vectors representing (in any order) all the squares that the knight can move to.

πŸ’‘ Hint: The outer product operator ∘. could be useful for generating the coordinates.

Examples

      (your_function) 5 4   ⍝ ]Box on is used to display the result
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”
β”‚3 3β”‚3 5β”‚4 2β”‚4 6β”‚6 2β”‚6 6β”‚7 3β”‚7 5β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜
      (your_function) 1 1
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”
β”‚2 3β”‚3 2β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”˜

5: Doubling Up

Given a word or a list of words, return a Boolean vector where 1 indicates a word with one or more consecutive duplicated, case-sensitive, letters. Each word will have at least one letter and will consist entirely of either uppercase (A–Z) or lowercase (a–z) letters. Words consisting of a single letter can be scalars.

πŸ’‘ Hint: The nest function βŠ†Y could be useful.

Examples

      (your_function) 'I' 'feed' 'the' 'bookkeeper'
0 1 0 1
      (your_function) 'I'
0
      (your_function) 'feed'
1
      (your_function) 'MY' 'LLAMAS' 'HAVE' 'BEEN' 'GOOD'
0 1 0 1 1 

6: Telephone Names

1 2ABC 3DEF
4GHI 5JKL 6MNO
7PQRS 8TUV 9WXYZ
* 0 #
Some telephone keypads have letters of the alphabet embossed on their keytops. Some people like to remember phone numbers by converting them to an alphanumeric form using one of the letters on the corresponding key. For example, in the keypad shown, 'ALSMITH' would correspond to the number 257-6484 and '1DYALOGBEST' would correspond to 1-392-564-2378.

Write an APL function that takes a character vector right argument that consists of digits and uppercase letters and returns an integer vector of the corresponding digits on the keypad.

πŸ’‘ Hint: Your solution might make use of the membership function X∊Y.

Examples

      (your_function) 'IAMYY4U'
4 2 6 9 9 4 8
      (your_function) ''   ⍝ should return an empty vector

      (your_function) 'UR2CUTE'
8 7 2 2 8 8 3

7: In the Center of It All

Given a right argument of a list of words (or possibly a single word) and a left argument of a width, return a character matrix that has width columns and one row per word, where each word is centered within the row. If width is smaller than the length of a word, truncate the word from the right. If there are an odd number of spaces to center within, leave the extra space on the right.

πŸ’‘ Hint: The mix ↑Y and rotate X⌽Y functions will probably be useful here.

Examples

      10 (your_function) 'APL' 'Problem' 'Solving' 'Competition'
   APL   
 Problem   
 Solving  
Competitio
      3 (your_function) 0β΄βŠ‚''   ⍝ result should be 0-row, 3-column matrix      

8: Going the Distance

Created by Causeway SVG engine - SharpPlot v3.61.0 Border ===== Region ===== X-Axis Ticks ===== X-Axis Grid X-Axis tickmarks Y-Axis Ticks ===== Y grid Y-Axis tickmarks Axes ===== Arrowhead(s) for the axes Y-axis labels Β―2 Β―1 1 2 3 for X-axis labels Β―2 Β―1 1 2 Heading, subheading and footnotes ===== Start of Line Chart =========== Points follow ... Line Data value labels ... A←(Β―1.5 Β―1.5) B←(1.5 2.5) C←(1.5 Β―1.5) Reset to original origin

Given a vector of (X Y) points, or a single X Y point, determine the total distance covered when travelling in a straight line from the first point to the next one, and so on until the last point, then returning directly back to the start. For example, given the points (A B C) ← (Β―1.5 Β―1.5)(1.5 2.5)(1.5 Β―1.5), the distance A to B is 5, B to C is 4 and C back to A is 3, for a total of 12.

πŸ’‘ Hint: The rotate X⌽Y and power X*Y functions might be useful.

Examples

      (your_function) (1 ¯1)(1 3)   ⍝ from A to B and back to A
8
      (your_function) (1 1)(1 2)(2 2)(2 1)   ⍝ from A to B to C to D to A
4
      (your_function) 5 5   ⍝ staying where we are
0
      (your_function) (1 1)(3 3)   ⍝ there and back again
5.656854249

9: Area Code Γ  la Gauss

Gauss’s area formula, also known as the shoelace formula, is an algorithm to calculate the area of a simple polygon (a polygon that does not intersect itself). It’s called the shoelace formula because of a common method using matrices to evaluate it. For example, the area of the triangle described by the vertices (2 4)(3 Β―8)(1 2) can be calculated by β€œwalking around” the perimeter back to the first vertex, then drawing diagonals between the columns as shown below. The pattern created by the intersecting diagonals resembles shoelaces, hence the name β€œshoelace formula”

πŸ’‘ Hint: You may want to investigate the rotate first XβŠ–Y function.

First place the vertices in order above each other:
2 4
3 Β―8
1 2
2 4
Sum the products of the numbers connected by the diagonal lines going down and to the right:

      (2Γ—Β―8)+(3Γ—2)+(1Γ—4)
Β―6
      
2 β”‚ 4
3 β”‚ Β―8
1 β”‚ 2
2 4
Next sum the products of the numbers connected by the diagonal lines going down and to the left:

      (4Γ—3)+(Β―8Γ—1)+(2Γ—2)
8
      
2 β”‚ 4
3 β”‚ Β―8
1 β”‚ 2
2 4

Finally, halve the absolute value of the difference between the two sums:

      0.5 Γ— | Β―6 - 8
7
      
2 β”‚ β”‚ 4
3 β”‚ β”‚ Β―8
1 β”‚ β”‚ 2
2 4

Given a vector of (X Y) points, or a single X Y point, return a number indicating the area circumscribed by the points.

Examples

      (your_function) (2 4)(3 Β―8)(1 2)
7
      (your_function) (1 1)   ⍝ a point has no area
0
      (your_function) (1 1)(2 2)   ⍝ neither does a line
0

10: Odds & Evens

Given a vector of words, separate the words into two vectors – one containing all the words that have an odd number of letters and the other containing all the words that have an even number of letters.

πŸ’‘ Hint: You may want to look into the dyadic form of the key operator X f⌸ Y.

Examples

      (your_function) 'the' 'plan' 'is' 'great'   ⍝ ]box on is used to display theresult
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”€β”β”‚β”Œβ”€β”€β”€β”€β”¬β”€β”€β”β”‚
β”‚β”‚theβ”‚greatβ”‚β”‚β”‚planβ”‚isβ”‚β”‚
β”‚β””β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜β”‚β””β”€β”€β”€β”€β”΄β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      (your_function) 'all' 'odd' ⍝ note the empty 2nd element of the result
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”
β”‚β”Œβ”€β”€β”€β”¬β”€β”€β”€β”β”‚β”‚
β”‚β”‚allβ”‚oddβ”‚β”‚β”‚
β”‚β””β”€β”€β”€β”΄β”€β”€β”€β”˜β”‚β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”˜
      (your_function) 'only' 'even' 'here' ⍝ note the empty 1st element of the result
β”Œβ”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚β”‚β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”β”‚
β”‚β”‚β”‚onlyβ”‚evenβ”‚hereβ”‚β”‚
β”‚β”‚β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜β”‚
β””β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜