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 instance, most bacteria have a GC-content significantly higher than 50%.
Write a function that:
💡 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:
💡 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:
💡 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:
(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 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:
💡 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:
💡 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:
💡 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:
💡 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:
💡 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) '⍒'
*****⍒