4,494
edits
Miraheze>Adám Brudzewsky |
m (→Grille cypher) |
||
(9 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
This page contains examples that show APL's strengths. The examples require minimal background and have no special dependencies. | This page contains examples that show APL's strengths. The examples require minimal background and have no special dependencies. If these examples are too simple for you, have a look at our [[advanced examples]]. | ||
[[ | |||
== Arithmetic mean == | == Arithmetic mean == | ||
Line 40: | Line 28: | ||
will transform a list of strings representing words into a comma-separated list: | will transform a list of strings representing words into a comma-separated list: | ||
<source lang=apl> | <source lang=apl> | ||
{⍺,', ',⍵}⌿'cow' 'sheep' 'cat' 'dog' | |||
┌────────────────────┐ | ┌────────────────────┐ | ||
│cow, sheep, cat, dog│ | │cow, sheep, cat, dog│ | ||
Line 124: | Line 112: | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]]}} | {{Works in|[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]]}} | ||
=== Frequency of characters in a string === | |||
The [[Outer Product]] allows for an intuitive way to compute the occurrence of characters at a given location in a string: | |||
<source lang=apl> | |||
'abcd' ∘.= 'cabbage' | |||
0 1 0 0 1 0 0 | |||
0 0 1 1 0 0 0 | |||
1 0 0 0 0 0 0 | |||
0 0 0 0 0 0 0 | |||
</source> | |||
Then it is simply a matter of performing a sum-reduce <source lang=apl inline>+/</source> to calculate the total frequency of each character:<ref name="Marshall LambaConf 2019">[[Marshall Lochbaum]] used this example as part of his talk on [[Outer Product]] at LambdaConf 2019.</ref> | |||
<source lang=apl> | |||
+/ 'abcd' ∘.= 'cabbage' | |||
2 2 1 0 | |||
</source> | |||
=== Parenthesis nesting level === | === Parenthesis nesting level === | ||
First we compare all characters to the opening and closing characters; | We can expand on the use of <source lang=apl inline>∘.</source> in the above example to perform more complex calculations. First we compare all characters to the opening and closing characters; | ||
<source lang=apl> | <source lang=apl> | ||
'()'∘.='plus(square(a),plus(square(b),times(2,plus(a,b)))' | '()'∘.='plus(square(a),plus(square(b),times(2,plus(a,b)))' | ||
Line 145: | Line 148: | ||
=== Grille cypher === | === Grille cypher === | ||
A [ | A [[wikipedia:grille (cryptography)|grille]] is a 500 year old method for encrypting messages. | ||
[[File:Grille.png|none|500px|frameless | [[File:Grille.png|none|500px|frameless|The application of a grille cypher]] | ||
<p> | <p> | ||
Represent both the grid of letters and the grille as character matrices. | Represent both the grid of letters and the grille as character matrices. | ||
Line 170: | Line 173: | ||
ILIKEAPL | ILIKEAPL | ||
</source> | </source> | ||
===References=== | |||
{{APL | <references/> | ||
{{APL development}} |