Write exercises
Remember, you can test your code out on TryAPL before submitting it here! You can submit as many solutions as you like.
Since this course is still a work-in-progress, solving the write exercises will currently not lead to any credits.
Write problem 1
Create a dfn that returns the string 'ABBCCCDDDDEEEEEFFFFFF...ZZZZZZZZZZZZZZZZZZZZZZZZZZ' (call it with any right argument, e.g. ABB ⍬)
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 (call it with any right argument, e.g. RATIO ⍬)
Hint: Use the reduce / operator with the correct function as its left operand
Write problem 5
Create a dfn that evaluates the following sum for a right argument ⍵
Hint: Use the reduce / operator
Write problem 6
Create a dfn that returns a 1 if every element of its left argument appears somewhere 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 greater than 1 that is not divisible by 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. If several letters occur equally often, return the one that occurs first.
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 of 0s and 1s: for each element of the vector right argument ⍵, that many 0s followed by a single 1.
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 2 3 4
OG CPD HXQO
Hint: One way is to create a random string of the right length including spaces, then use the function of the previous exercise to place the spaces