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 vector consisting of the first ten prime numbers called PRIMES
Write problem 2
Create a vector called POWER of value 2 to the power of PRIMES, minus two
Write problem 3
Divide the vector POWER by PRIMES
Write problem 4
Create the word "BUNNY" by indexing the alphabet vector ⎕A
Write problem 5
The following matrix CIPHER consists of shifted versions of the alphabet for every row.
CIPHER ← (26 27 ⍴ ⎕A)[;1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]
CIPHER
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY
The Caesar cipher encrypts a phrase by shifting all its letters by a specific amount along the alphabet. For example, "ARENA" becomes "RIVER" under a shift of 17 places. Use indexing of the above matrix to encipher the word "BUNNY" by shifting its letters 17 places.
Write problem 6
Consider the following ASCII art stored in a matrix called ART, shown here with its row and column numbers.
123456789111111111122222222
012345678901234567
1 ._________________.
2 |.---------------.|
3 || __ ____ __ ||
4 || / _\( _ ( ) ||
5 ||/ \) __/ (_/||
6 ||\_/\_(__) \____||
7 ||_______________||
8 /.-.-.-.-.-.-.-.-.\
9 /.-.-.-.-.-.-.-.-.-.\
10 /.-.-.-.-.-.-.-.-.-.-.\
11 /______/__________\_____\
12 \_______________________/
Create a matrix called APL which consists of the following subarray obtained by indexing ART
__ ____ __
/ _\( _ ( )
/ \) __/ (_/
\_/\_(__) \____
Write problem 7
Create a 3 by 3 grid of 'X's and 'O's called BOARD
Write problem 8
Considering the above array as a game of noughts and crosses, change a single element to make the O player win.
Write problem 9
Given the coefficients list C of a quadratic \(P(x) = C[1] x^2 + C[2] x + C[3]\), evaluate the polynomial for a value X. For example, for C ← 1 2 3, and X ← 10, this should evaluate to $ 1 \cdot 10^2 + 2 \cdot 10 + 3 = 123 $.
Write problem 10
Consider the following list of GAMES
GAMES ← 5 24 ⍴ 'CHESS CHECKERS BACKGAMMON POKER GLOBAL THERMONUCLEAR WAR'
GAMES
CHESS
CHECKERS
BACKGAMMON
POKER
GLOBAL THERMONUCLEAR WAR
Get the first letter of each of the games listed using indexing
Write problem 11
Get the first three letters of the second and fifth game listed above using indexing
Write problem 12
Consider the following matrix ROUND of the outcomes of a game of rock, paper, scissors.
ROUND ← 3 3 ⍴ 'DRAW' 'P2 COVERS' 'P1 BLUNTS' 'P1 COVERS' 'DRAW' 'P2 CUTS' 'P2 BLUNTS' 'P1 CUTS' 'DRAW'
ROUND
┌─────────┬─────────┬─────────┐
│DRAW │P2 COVERS│P1 BLUNTS│
├─────────┼─────────┼─────────┤
│P1 COVERS│DRAW │P2 CUTS │
├─────────┼─────────┼─────────┤
│P2 BLUNTS│P1 CUTS │DRAW │
└─────────┴─────────┴─────────┘
The rows specify the move made by player 1, and the columns the move made by player 2, both in the order ROCK, PAPER, SCISSORS.
Using indexing, find the outcome of the round in which player 1 plays scissors and player 2 plays paper.