A DNA string is composed of the letters ‘A’,’C’,’G’ and ‘T’. The GC-content of a DNA string is given by the percentage of the symbols in the string that are either ‘C’ or ‘G’. Very small discrepancies in GC-content can be used to distinguish species; for instan`ce, most bacteria have a GC-content significantly higher than 50%.

Write a function that:

- has a right argument that is a non-empty character vector representing a DNA string.
- returns the percentage of GC-content in the string.

💡 Hint: The *membership* function X∊Y could be helpful for this problem.

```
(your_function) 'GCGCGCGCCCGGGGCCG'
100
(your_function) 'ACGTACGTACGTACGT'
50
(your_function) 10 12 16 10/'ACGT'
58.33333333
```

Write a function that behaves like the APL *index-of* function R←X⍳Y except that it returns 0 instead of 1+≢X for elements of Y not found in X.

```
'DYALOG' (your_function) 'APL'
3 0 4
(5 5⍴⎕A) (your_function) ↑'UVWXY' 'FGHIJ' 'XYZZY'
5 2 0
```

Write a function that:

- has a right argument Y which is an integer vector or scalar
- has a left argument X which is also an integer vector or scalar
- finds which elements of Y are multiples of each element of X and returns them as a vector (in the order of X) of vectors (in the order of Y).

💡 Hint: The *residue* function X|Y and *outer product* operator X∘.fY might be useful for this problem.

```
⎕←Y←20?20 ⍝ your example may be different
5 7 8 1 12 10 20 16 11 4 2 15 3 18 14 19 13 9 17 6
2 4 7 3 9 (your_function) Y ⍝ using ]Box on
┌─────────────────────────┬────────────┬────┬──────────────┬────┐
│8 12 10 20 16 4 2 18 14 6│8 12 20 16 4│7 14│12 15 3 18 9 6│18 9│
└─────────────────────────┴────────────┴────┴──────────────┴────┘
3 (your_function) ⍳10
┌─────┐
│3 6 9│
└─────┘
6 7 (your_function) 42
┌──┬──┐
│42│42│
└──┴──┘
2 3 5 (your_function) ⍬ ⍝ returns a vector of 3 empty vectors
┌┬┬┐
││││
└┴┴┘
⍬ (your_function) ⍳10 ⍝ returns an empty vector
```

Write a function that:

- takes a right argument which is an array of positive numbers representing circle diameters
- returns a numeric array of the same shape as the right argument representing the difference between the areas of the circles and the areas of the largest squares that can be inscribed within each circle

💡 Hint: The *pi times* function ○Y could be helpful.

```
(your_function) 2×⍳5
1.141592654 4.566370614 10.27433388 18.26548246 28.53981634
(your_function) (2*.5)×3 3 ⍴⍳9
0.5707963268 2.283185307 5.137166941
9.132741229 14.26990817 20.54866776
27.96902001 36.53096491 46.23450247
```

Suppose you have a number of trees that you want to plant in a rectangular pattern with complete rows and columns, meaning all rows have the same number of trees. You also want that rectangular pattern to be as “square” as possible, meaning there is a minimal difference between the number of rows and columns in the pattern.

Write a function that:

- has a right argument
**N**which is a positive integer less than or equal to 1,000,000. - returns a 2-element integer vector R representing the rows and columns of the rectangle such that:
- N=×/R meaning N equals the number of rows × the number of columns (you planted all the trees!)
- ≤/R meaning the number of rows is less than or equal to the number of columns
- |-/R is minimal, meaning the difference between the elements of R is as small as possible

```
(your_function) 12
3 4
(your_function) 16
4 4
(your_function)¨⍳19
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────┬───┬────┬───┬───┬───┬────┬───┬────┐
│1 1│1 2│1 3│2 2│1 5│2 3│1 7│2 4│3 3│2 5│1 11│3 4│1 13│2 7│3 5│4 4│1 17│3 6│1 19│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴────┴───┴────┴───┴───┴───┴────┴───┴────┘
(your_function)¨999999 1000000
┌────────┬─────────┐
│999 1001│1000 1000│
└────────┴─────────┘
```

According to Wikipedia, Fischer random chess is a variation of the game of chess invented by former world chess champion Bobby Fischer. Fischer random chess employs the same board and pieces as standard chess, but the starting position of the non-pawn pieces on the players' home ranks is randomized, following certain rules. White's non-pawn pieces are placed on the first rank according to the following rules:

- The Bishops must be placed on opposite-color squares.
- The King must be placed on a square between the rooks.

The good news is that you don't actually need to know anything about chess to solve this problem! We'll use strings whose elements are 'KQRRBBNN' for the King (♔), Queen (♕), 2 Rooks (♖), 2 Bishops (♗), and 2 kNights (♘) respectively.

Write a function that:

- has a character vector right argument that is a permutation of 'KQRRBBNN'
- returns 1 if the following are true:
- the K is between the two Rs
- the Bs occupy one odd and one even position

💡 Hint: The *where* function ⍸Y and the *residue* function X|Y could help with solving this problem.

```
(your_function) 'RNBQKBNR' ⍝ standard chess layout
1
(your_function) 'BBNRKNRQ' ⍝ layout in diagram above
1
(your_function) 'RBBNQNRK' ⍝ K not between Rs
0
(your_function) 'BRBKRNQN' ⍝ Bs both in odd positions
0
```

Wikipedia states that, in recreational mathematics, a square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row, each column, and both main diagonals are the same.

Write a function to test whether an array is a magic square. The function must:

- have a right argument that is a square matrix of integers (not necessarily all positive integers)
- return 1 if the array represents a magic square, otherwise return 0

💡 Hint: The *dyadic transpose* X⍉Y function could be helpful for solving this problem.

```
(your_function) 1 1⍴42
1
(your_function) 3 3⍴4 9 2 3 5 7 8 1 6
1
(your_function) 2 2⍴1 2 3 4
0
```

Write a function that:

- has a right argument that is a numeric scalar or vector of length up to 3, representing a number of [[[days] hours] minutes] – a single number represents minutes, a 2-element vector represents hours and minutes, and a 3-element vector represents days, hours, and minutes.
- has a similar left argument, although not necessarily the same length as the right argument.
- returns a single number representing the magnitude of the difference in minutes between the arguments.

💡 Hint: The functions *decode* X⊥Y and *take* ↑ could be useful for this problem.

```
2 30 (your_function) 5 15
165
5 15 (your_function) 2 30
165
1 0 0 (your_function) 0 ⍝ number of minutes in a day
1440
1 0 0 (your_function) ⍬ ⍝ don't forget to handle empty arguments!
1440
1 0 (your_function)¯1 0
120
1.5 0 (your_function) 90
0
```

Write a function that:

- has a right argument that is a numeric vector of 2 or more elements representing daily prices of a stock.
- returns an integer singleton that represents the highest number of consecutive days where the price increased, decreased, or remained the same, relative to the previous day.

💡 Hint: The *N-wise reduction* operator X f/ Y function could be useful when solving this problem.

(your_function) 1 2 3 5 5 5 6 4 3 3 (your_function) 1 2 3 4 4 4 4 4 5 4 3 4 (your_function) 1 2 1

Write a function that:

- has a right argument T that is a character scalar, vector or a vector of character vectors/scalars.
- has a left argument W that is a positive integer specifying the width of the result.
- returns a right-aligned character array R«/span> of shape ((2=|≡T)/≢T),W meaning R is one of the following:
- a W-wide vector if T is a simple vector or scalar.
- a W-wide matrix with the same number rows as elements of T if T is a vector of vectors/scalars.

- if an element of T has length greater than W, truncate it after W characters.

💡 Hint: Your solution might make use of *take*
X ↑ Y.

In these examples, ⍴⎕← is inserted to display first the result and then its shape.

```
⍴⎕←6 (your_function) '⍒'
⍒
6
⍴⎕←8 (your_function) 'K' 'E' 'Iverson'
K
E
Iverson
3 8
⍴⎕←10 (your_function) 'Parade'
Parade
10
⍴⎕←8 (your_function) 'Longer Phrase' 'APL' 'Parade'
r Phrase
APL
Parade
3 8
starsForSpaces←'*'@(=∘' ')
starsForSpaces 6 (your_function) '⍒'
*****⍒
```