-
Notifications
You must be signed in to change notification settings - Fork 1
/
selection.html
103 lines (95 loc) · 3.07 KB
/
selection.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dyalog APL Workshop</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="oneliners.css" />
<script src="util.js"></script>
<script src="tio-dyalog.js"></script>
<script src="testString.js"></script>
<script src="problems.js"></script>
<script src="pako.min.js"></script>
</head>
<body>
<h1>Part 3: Selecting from lists</h1>
<div class="tab">
<h3>Indexing lists</h3>
<div class="description">
<p>
In many other programming languages, "selection" is used to describe control structures such as "if then else" or "select case". In APL, we can get a similar effect by literally "selecting" elements from arrays.
</p>
</div>
<pre class="apl">
'APPLE'[1 3 4] ⍝ Select elements 1, 3 and 4
APL
⍸ 1 0 0 1 0 1 ⍝ Where are the 1s?
1 4 6
(⍳5) IsDivisibleBy 2 ⍝ 1 Where ⍺ is even
0 1 0 1 0
{⍵[⍸⍵ IsDivisibleBy 123]}⎕AVU ⍝ Numbers in ⎕AVU divisible by 123
0 123 8364 246
</pre>
</div>
<div class="tab">
<div class="description">
<ol>
<li>
<h3>Simple Simon says select these elements</h3>
<ol type="a">
<li>
Write a function to get even numbers from a numeric list.
<pre class="apl">
Even ⍳10
2 4 6 8 10
Even 1 17 19 22 32 15
22 32
</pre>
</li>
<li>
Write a function to get numbers which are divisible by <code class="apl">5</code> from a numeric list.
<pre class="apl">
Div5 ⍳50
5 10 15 20 25 30 35 40 45 50
Div5 12 13 15 20 19 55 16
15 20 55
</pre>
</li>
<li>
Write a function to get numbers which are divisible by <code class="apl">⍺</code> from a numeric list.
<pre class="apl">
3 Div ⍳30
3 6 9 12 15 18 21 24 27 30
7 Div 11 17 21 42 18 7 0 70
21 42 7 0 70
</pre>
</li>
</ol>
</li>
<li>
<h3>Without without</h3>
Not using <code class="apl">~</code></strong>, write a dfn which removes spaces from a text vector.
<pre class="apl">
NoSpace'here is some text'
hereissometext
NoSpace'there are more spaces here'
therearemorespaceshere
</pre>
</li>
<li>
<h3>sdrawkcab s'taht woN</h3>
Not using <code class="apl">⌽</code>, write a dfn which reverses its right argument.
<pre class="apl">
Reverse 'Some characters'
sretcarahc emoS
Reverse ⍳10
10 9 8 7 6 5 4 3 2 1
</pre>
</li>
</ol>
</div>
</div>
<a class="apl nav right" href="rank2.html">Next →</a>
<a class="apl nav left" href="dfns.html">← Back</a>
</body>
</html>