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.
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β
βββ
|
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
.
(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
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.
(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
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.
(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β
βββββ΄ββββ
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.
(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
|
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
.
(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
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.
10 (your_function) 'APL' 'Problem' 'Solving' 'Competition'
APL
Problem
Solving
Competitio
3 (your_function) 0β΄β'' β result should be 0-row, 3-column matrix
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.
(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
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: |
|
||||||||||||||||
Sum the products of the numbers connected by the diagonal lines going down and to the right:
(2ΓΒ―8)+(3Γ2)+(1Γ4) Β―6 |
|
||||||||||||||||
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 |
|
||||||||||||||||
Finally, halve the absolute value of the difference between the two sums: 0.5 Γ | Β―6 - 8 7 |
|
Given a vector of (X Y)
points, or a single X Y
point, return a number indicating the area circumscribed by the points.
(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
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
.
(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ββ
ββββββββ΄βββββ΄ββββββ
ββ΄βββββββββββββββββ