-
Notifications
You must be signed in to change notification settings - Fork 1
/
problems.html
175 lines (170 loc) Β· 6.41 KB
/
problems.html
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>APL Problem Sets</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="oneliners.css" />
<script src="tio-dyalog.js"></script>
<script src="testString.js"></script>
<script src="problems.js"></script>
<script src="pako.min.js"></script>
</head>
<body>
<!-- Add <div class="tab"> for each problem -->
<!-- Tab buttons created by tabs.js -->
<!-- Language bar, input field and submit button included by tabs.js -->
<h1>APL one-liners</h1>
<div id="tabContainer"></div>
<div id="P0" class="tab">
<h3>1: Counting Vowels</h3>
<div class="description">
<p>
Write a function to count the number of vowels (A,E,I,O,U) in an array consisting of uppercase letters (A-Z).
<br /><br />
<strong>π‘ Hint:</strong> The membership function <a class="apl" target="_blank" href="http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Membership.htm">β</a> could be helpful for this problem.
</p>
</div>
<h4>Examples</h4>
<pre class="apl">
(your_function) 'COOLAPL'
3
(your_function) '' β Empty argument
3
(your_function) 'NVWLSHR'
3
</pre>
</div>
<div id="P1" class="tab">
<h3>2: Making the Grade</h3>
<div class="description">
<table class="border">
<tr>
<td><strong>Score Range</strong></td>
<td><strong>Letter Grade</strong></td>
</tr>
<tr>
<td>0-64</td>
<td>F</td>
</tr>
<tr>
<td>65-69</td>
<td>D</td>
</tr>
<tr>
<td>70-79</td>
<td>C</td>
</tr>
<tr>
<td>80-89</td>
<td>B</td>
</tr>
<tr>
<td>90-100</td>
<td>A</td>
</tr>
</table>
<p>
Write a function that, given an array of integer test scores in the inclusive range 0β100, returns an identically-shaped array of the corresponding letter grades according to the table to the left.
<br /><br />
<strong>π‘ Hint:</strong> You may want to investigate the interval index function <a class="apl" target="_blank" href="http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Interval%20Index.htm">βΈ</a>
</p>
</div>
<h4>Examples</h4>
<pre class="apl">
(your_function) 0 64 65 69 70 79 80 89 90 100
FFDDCCBBAA
(fn) β¬ β returns an empty vector
(fn) 2 3β΄71 82 81 82 84 59
CBB
BBF
</pre>
</div>
<div id="P2" class="tab">
<h3>3: Telephone Names</h3>
<div class="description">
<table class="telephone">
<tbody><tr>
<td><ruby>1<rt></rt></ruby></td>
<td><ruby>2<rt>ABC</rt></ruby></td>
<td><ruby>3<rt>DEF</rt></ruby></td>
</tr>
<tr>
<td><ruby>4<rt>GHI</rt></ruby></td>
<td><ruby>5<rt>JKL</rt></ruby></td>
<td><ruby>6<rt>MNO</rt></ruby></td>
</tr>
<tr>
<td><ruby>7<rt>PQRS</rt></ruby></td>
<td><ruby>8<rt>TUV</rt></ruby></td>
<td><ruby>9<rt>WXYZ</rt></ruby></td>
</tr>
<tr>
<td><ruby>*<rt></rt></ruby></td>
<td><ruby>0<rt></rt></ruby></td>
<td><ruby>#<rt></rt></ruby></td>
</tr>
</tbody></table>
<p>
Some telephone keypads have letters of the alphabet embossed on their keytops. Some people like to remember phone numbers by converting them to an alphanumeric form using one of the letters on the corresponding key. For example, in the keypad shown, <code class="apl">'ALSMITH'</code> would correspond to the number 257-6484 and <code class="apl">'1DYALOGBEST'</code> would correspond to 1-392-564-2378.
Write an APL function that takes a character vector right argument that consists of digits and uppercase letters and returns an integer vector of the corresponding digits on the keypad.
<br /><br />
<strong>π‘ Hint:</strong> You might want to use the membership function <a class="apl ngn_tt" target="_blank" href="http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Membership.htm">β</a>
</p>
<br />
</div>
<h4>Examples</h4>
<pre class="apl">
(your_function) 'IAMYY4U'
4 2 6 9 9 4 8
(your_function) '' β Returns an empty vector
(your_function) 'UR2CUTE'
8 7 2 2 8 8 3
</pre>
</div>
<div id="P3" class="tab">
<h3>4: Grille Cypher</h3>
<div class="description">
<p>
A Grille is a cryptographic device consisting of a square sheet with holes cut out, which when laid ontop of a similarly sized character matrix reveals a hidden message (see image below).
<img src="img/Grille.png" width=60%/><br>
Representing a Grilleas an <strong>n Γ n</strong> character matrix, using a hash ('#') to mean opaque material and a blank (' ') to meana hole, write a function which takes a grille to the left and a character matrix of the same shape tothe right, producing the hidden message as a character vector.
</p>
</div>
<h4>Examples</h4>
<pre class="apl">
(2 2β΄'# # ') (your_function) 2 2β΄'LHOI'
HI
gβ6 6β΄'#### ## # #### # ######## # ## ####'
cβ6 6β΄'OBAATIFHRISZOADIFSVJJXXBBHFQUBONVSKH'
g c
ββββββββ¬βββββββ
β#### #βOBAATIβ
β# # #βFHRISZβ
β### # βOADIFSβ
β######βVJJXXBβ
β## # #βBHFQUBβ
β# ####βONVSKHβ
ββββββββ΄βββββββ
g (your_function) c
THISISFUN
</pre>
</div>
<div id="P4" class="tab">
<h3>5: Moving Average</h3>
<div class="description">
<p>
Write a function to calculate the n-wise rolling average of the rows of an array.
</p>
</div>
<h4>Examples</h4>
<pre class="apl">
3(your_function)4 5 5 3 4 1 2
14 13 12 8 7
6(your_function)73 8 2 100 6 31 20 50 32 1
220 167 209 239 140
</pre>
</div>
<script src="tabs.js"></script>
</body>
</html>