# Write exercises

Submit APL code for the following exercises. Your submissions are graded using TMC.

Make sure to log in to be able to submit your work!

Remember, you can test out ideas and develop you solution at TryAPL before submitting it here.

You can submit as many solutions as you like. If you submit a correct solution at least once, you will receive points on the TMC server and be able to see the model solution.

If the write problem is red, it is unsolved. If it it green, you have solved it and received points for it on the server.

Write problem 1

Create a dfn that returns the string 'ABBCCCDDDDEEEEFFFFF...ZZZZZZZZZZZZZZZZZZZZZZZZZZ'

Write problem 2

Create a dfn that returns the vector ⍺, ⍺+1, ⍺+2, ⍺+3, ..., ⍵

Write problem 3

Create a dfn that returns the vector ⍺, ⍺+⍵[1], ⍺+2×⍵[1], ⍺+3×⍵[1], ..., ⍺+⍵[2]×⍵[1]

```
1 step 10 10
1 11 21 31 41 51 61 71 81 91 101
2 step 0.5 5
2 2.5 3 3.5 4 4.5
```

Write problem 4

Create a dfn that evaluates the following continued fraction to 100 1s $$ 1+\frac{1}{1+\frac{1}{1+\frac{1}{\ldots}}} $$

Hint: Use the reduce / operator with the right function left argument

Write problem 5

Create a dfn that evaluates the following sum $$ \sum_{n=0}^{100} \frac{1}{n^2} $$

Hint: Use the reduce / operator

Write problem 6

Create a dfn that returns a 1 if its left argument is totally contained in its right argument, and 0 otherwise.

```
1 1 2 3 SUBSET 1 2 3 4 5
1
'MEOW' SUBSET 'HOMEOWNER'
1
'I' SUBSET 'TEAM'
0
```

Write problem 7

Create a dfn that returns 1 if `⍵`

is prime, and 0 otherwise. A prime number is one that does not divide any number other than itself and 1, that is, the remainder of division is 0 only for 1 and `⍵`

.

Write problem 8

Create a dfn that takes in a string right argument and returns the most common letter.

Write problem 9

The most common letter in the english language is the letter 'E'. A simple method of obtaining the shift (and thus deciphering) Caesar ciphered text is to look at the most common letter, and shift it back to 'E'. For example, 'GURBJYFNERABGJUNGGURLFRRZ' has most common letter 'R', shifting back 13 spaces gives us 'THEOWLSARENOTWHATTHEYSEEM'.

Create a dfn that applies this algorithm to a string right argument.

Write problem 10

Create a dfn that generates a random word of length `⍵`

.

```
WORD 10
OJCCKXBSVA
WORD 5
SBURB
```

Write problem 11

Create a dfn that generates an array with 1s separated by 0s, where the length of each run of 0s is specified by a vector right argument `⍵`

.

```
RUN 2 3 4
0 0 1 0 0 0 1 0 0 0 0 1
RUN 10
0 0 0 0 0 0 0 0 0 0 1
```

Hint: One way is to use ∊ member of and + plus scan

Write problem 12

Create a dfn that generates random words with lengths specified by its right vector argument `⍵`

.

```
PHRASE 3 4 5
OG CPD HXQO
```

Hint: One way is to use ∊ member of and + plus scan