« first day (1055 days earlier)      last day (1600 days later) » 

5:00 PM
@EdgyNerd Not really. Just like there isn't a smarter way to do so in TMN. You could a parenthesis or use another operator, but it is basically the same.
 
oh ok
 
It is actually my favourite operator: It looks all confused because right and left have been turned around:
⍞←10-⍨2
 
@Adám ¯8
 
oh ok
 
So takes a single function as its operand (just like /) but derives a dyadic function which is the same as the original, but with swapped arguments.
 
5:02 PM
makes sense
 
Actually, the derived function can also be used monadically. Then it it means "selfie" (hey, the symbol even looks like a selfie) in the sense that the dyadic function is applied with the single right argument used as both arguments:
⍞←+⍨3
 
@Adám 6
 
So +⍨ is the "double" function and ×⍨ is the "square" function.
And again, any function can be used.
 
oh wow
does every operator have a monadic form?
 
You probably mean function, not operator.
 
5:05 PM
oh yeah oops
 
And no, some symbols don't have any defined meaning for their monadic form. Yet, at least.
 
oh ok
⍞←÷1 2 3
 
@EdgyNerd 1 0.5 0.3333333333
 
Note that operators are always exclusively monadic or exclusively dyadic.
 
is that the difference between them?
(functions and operators)
 
5:07 PM
Functions take one or two arrays and return an array. Operators take one or two operands (each can be either an array and/or a function) and return a derived function.
 
oh ok
 
@EdgyNerd Challenge: Using just the primitives (built-ins) you've learned here, can you write an expression to find the length of a numeric list. E.g. for the list 2 7 1 8 it should give 4.
 
⍞←1 ÷ 3 1 5 6
 
@EdgyNerd 0.3333333333 1 0.2 0.1666666667
 
wait no
I'm trying to think of a way to make all of the numbers into 1
 
5:10 PM
Right, that's the right way.
 
(eg: dividing them by themselves, but that wouldn't work for 0)
does it need to work for 0?
 
@EdgyNerd Actually, it would. Surprise:
⍞←0÷0
 
@Adám 1
 
oh wow
⍞←+/÷⍨1 4 2 7
 
@EdgyNerd 4
 
5:11 PM
is that it?
 
Yes, that's it.
 
oh wow
 
Of course, APL has a built-in way to get the length, but this was to give you some exercise.
You know that the arithmetic mean (a.k.a. the average) is the sum divided by the length, right?
 
yeah
 
What is the arithmetic mean of 3 1 4 1 5?
 
5:13 PM
2.8?
 
Sure, but as an APL expression ;-)
 
oh ok
haha
 
I'm looking for something like ⋄ list←3 1 4 1 5 ⋄ ⎕←something list something list
 
⋄ list←3 1 4 1 5 ⋄ +/list÷+/÷⍨list
isn't that meant to work with the bot?
 
You need ⎕← to output.
 
5:16 PM
oh yeah
⋄ list←3 1 4 1 5 ⋄ ⎕←+/list÷+/÷⍨list
 
@EdgyNerd
2.8
 
oh wow it worked
 
Very nice.
 
is there a way to do that without defining it to a variable?
 
Yes, let's talk user-defined functions.
The Greek alphabet begins with (alpha) and ends with (omega), that is, is the leftmost character and is the rightmost.
 
5:19 PM
oh ok
 
We therefore use to mean the left argument (which is optional) and to mean the right argument. The function is in curly braces:
⍞←3 {⍺+⍵} 4
 
@Adám 7
 
oh ok
 
Try doing the average as an inline function!
 
⍞←{+/⍵÷+/÷⍨⍵}2 6 3 6 2
 
5:21 PM
@EdgyNerd 3.8
 
Yup.
You can of course also stick such anonymous user-defined function (we call them "dfns" pronounced /dee-funs/) into a name:
⋄ Avg←{+/⍵÷+/÷⍨⍵} ⋄ ⎕←Avg 3 1 4 1 5
 
@Adám
2.8
 
oh ok
 
On all regards, such functions work exactly like APL's built-in functions.
Do you want more?
 
sure
 
5:23 PM
Are you familiar with prime numbers?
 
yeah
 
Great. I'll give you a couple of more functions then: is called floor (the symbol is a stylised wall with a piece of the floor) and rounds numbers down:
⍞←⌊2.3 4 ¯0.5
 
@Adám 2 4 ¯1
 
Can you guess what the symbol and function name is for rounding up?
 
 
5:25 PM
Up?
 
wait oops
⍞←⌈5.5
 
@EdgyNerd 6
 
Yup. OK, now I have a real challenging one for you. Take your time and maybe build it piece for piece. Write a function IsDivisibleBy such that 15 IsDivisibleBy 5 gives 1 and 15 IsDivisibleBy 6 gives 0.
 
⍞←15{1=⍺/⍵}5
 
@EdgyNerd 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 
5:27 PM
wait no
⍞←15{1=⍺÷⍵}5
 
@EdgyNerd 0
 
wait no oops
 
Don't worry. Experimenting is fine. That's how most APLers code.
 
⍞←15{{⍵=⌊⍵}⍺÷⍵}5
 
@EdgyNerd 1
 
5:29 PM
is that right?
⍞←15{{⍵=⌊⍵}⍺÷⍵}6
 
@EdgyNerd 0
 
@EdgyNerd Not only is it right, it is a really nice solution.
 
oh wow
 
So here's something really cool:
⍞←15{{⍵=⌊⍵}⍺÷⍵}5 6
 
@Adám 1 0
 
5:30 PM
oh wow that works
 
If you write your functions properly, you get auto-mapping for free!
 
what would be an example of a function not written properly for that? (so without auto-mapping)
 
In general, you should strive to write your code like that. It makes for "good APL".
@EdgyNerd You'll see in a moment.
Now write a function IsPrime that given a number answers if it is a prime or not. IsPrime 13 should give 1 and IsPrime 14 should give 0.
 
⍞←{0>+/{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}13 14
 
@EdgyNerd VALUE ERROR
 
5:35 PM
oh wait
⍞←{1+⍳⍵-2}13
 
@EdgyNerd 2 3 4 5 6 7 8 9 10 11 12
 
⍞←{{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}} 15
 
@EdgyNerd      ∇{{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}
 
⍞←{{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}}15
 
@EdgyNerd Don't try to do it for two numbers at a time. Just do one at a time.
 
5:36 PM
⍞←{0>+/{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}13
 
@EdgyNerd VALUE ERROR
 
@EdgyNerd Your inner function {{⍵=⌊⍵}⍺÷⍵} needs a left argument.
 
oh right
⍞←{{⍵{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}}15
 
@EdgyNerd      ∇{{⍵{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}
 
@EdgyNerd You have a mismatched number of braces there.
 
5:38 PM
⍞←{⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}}15
 
@EdgyNerd      ∇{⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}
 
⍞←{⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}15
 
@EdgyNerd 0 1 0 1 0 0 0 0 0 0 0 0 0
 
@EdgyNerd Good so far.
 
⍞←{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}13
 
5:39 PM
@EdgyNerd 1
 
⍞←{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}13 14
 
@EdgyNerd RANK ERROR
 
⍞←{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}14
 
@EdgyNerd 0
 
@EdgyNerd Uh oh, one number at a time.
 
5:39 PM
why doesn't that work with multiple numbers?
 
@EdgyNerd Because it contains which doesn't work map on multiple numbers (it does something better actually).
 
⍞←⍳5 10
 
@EdgyNerd  1 1  1 2  1 3  1 4  1 5  1 6  1 7  1 8  1 9  1 10
 
That only shows the first line of output:
⎕←⍳3 4
 
@Adám
┌───┬───┬───┬───┐
│1 1│1 2│1 3│1 4│
├───┼───┼───┼───┤
│2 1│2 2│2 3│2 4│
├───┼───┼───┼───┤
│3 1│3 2│3 3│3 4│
└───┴───┴───┴───┘
 
5:41 PM
what is that?
 
Just like ⍳5 gives the indices (coordinates) in a 1-dimensional system up until the point (5) so does ⍳3 4 give the indices in a 2-dimensional system up until the point (3,4).
 
oh ok
 
OK, I'll give you one last operator, the "table" operator (or "outer product" in fancy-speech):
⎕←1 2 3∘.+40 50 60 70
 
@Adám
41 51 61 71
42 52 62 72
43 53 63 73
 
Do you understand what it does?
 
5:45 PM
not really
 
Here is your multiplication table from school:
⎕←(⍳5)∘.×(⍳10)
 
@Adám
1  2  3  4  5  6  7  8  9 10
2  4  6  8 10 12 14 16 18 20
3  6  9 12 15 18 21 24 27 30
4  8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
 
⎕←1 3 5 6 ∘.+ 6 3 6 2
 
@EdgyNerd
 7 4  7 3
 9 6  9 5
11 8 11 7
12 9 12 8
 
It takes the list on the left going down and the list on the right going across and applies the given function to all combinations.
 
5:47 PM
oh ok
how would I make my prime function from earlier work with multiple numbers?
 
That's pretty much the next task. You can use any function instead of + or -, e.g. your IsDivisibleBy function from above. Using this info, create a function Primes which returns all the primes up to its argument. E.g Primes 10 should return 2 3 5 7
I have to go now, but I'll check in later to see how you fared.
 
oh ok, cya
⎕←5{(⍳⍺)∘.{⍺{⍵=⌊⍵}(⍳⍵)}6
⎕←5{(⍳⍺)∘.{⍺{⍵=⌊⍵}}(⍳⍵)}6
 
@EdgyNerd
SYNTAX ERROR
 
⎕←5{(⍳⍺)∘.{{⍵=⌊⍵}⍺÷⍵}(⍳⍵)}6
 
@EdgyNerd
1 0 0 0 0 0
1 1 0 0 0 0
1 0 1 0 0 0
1 1 0 1 0 0
1 0 0 0 1 0
 
5:56 PM
⎕←5{(1+⍳⍺)∘.{{⍵=⌊⍵}⍺÷⍵}(1+⍳⍵)}6
 
@EdgyNerd
1 0 0 0 0 0
0 1 0 0 0 0
1 0 1 0 0 0
0 0 0 1 0 0
1 1 0 0 1 0
 
⎕←5{(1+⍳⍺-1)∘.{{⍵=⌊⍵}⍺÷⍵}(1+⍳⍵-1)}6
 
@EdgyNerd
1 0 0 0 0
0 1 0 0 0
1 0 1 0 0
0 0 0 1 0
 
i'm so confused what I've done
⎕←{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}⍳⍵}
 
@EdgyNerd
{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}⍳⍵}
 
6:02 PM
⎕←{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}⍳⍵}10
 
@EdgyNerd
DOMAIN ERROR
 
⎕←{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+⍳⍵-2}1+⍳⍵-1}10
 
@EdgyNerd
RANK ERROR
 
oh yeah
I'm kinda stuck/confused
can you ping me when you get back later @Adám
⎕←{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}/1+⍳⍵-2}1+⍳⍵-1}10
 
@EdgyNerd
LENGTH ERROR
 
6:12 PM
⎕←{{0=+/⍵{{⍵=⌊⍵}⍺÷⍵}1+({⍳⍵}⍵)-2}1+⍳⍵-1}10
 
@EdgyNerd
WS FULL
 
⎕←{⍳⍵}1 2 4
 
@EdgyNerd
┌─────┬─────┬─────┬─────┐
│1 1 1│1 1 2│1 1 3│1 1 4│
├─────┼─────┼─────┼─────┤
│1 2 1│1 2 2│1 2 3│1 2 4│
└─────┴─────┴─────┴─────┘
 
⎕←{{⍺+⍳⍵}/()+⍵}1 2 4
 
@EdgyNerd
SYNTAX ERROR
 
6:18 PM
⎕←{{⍺+⍳⍵}/(,)⍵}1 2 4
 
@EdgyNerd
┌─────────────────────────────────────────────────┐
│┌───────┬───────┬───────┬───────┬───────┬───────┐│
││2 2 2 2│2 2 2 3│2 2 2 4│2 2 2 5│2 2 2 6│2 2 2 7││
│├───────┼───────┼───────┼───────┼───────┼───────┤│
││2 2 3 2│2 2 3 3│2 2 3 4│2 2 3 5│2 2 3 6│2 2 3 7││
│├───────┼───────┼───────┼───────┼───────┼───────┤│
││2 2 4 2│2 2 4 3│2 2 4 4│2 2 4 5│2 2 4 6│2 2 4 7││
│├───────┼───────┼───────┼───────┼───────┼───────┤│
││2 2 5 2│2 2 5 3│2 2 5 4│2 2 5 5│2 2 5 6│2 2 5 7││
│├───────┼───────┼───────┼───────┼───────┼───────┤│
 
⎕←{{⍺+⍳⍵}/((,),⍵)}1 2 4
⎕←{{⍺+⍳⍵}/((),⍵)}1 2 4
 
@EdgyNerd
SYNTAX ERROR
 
@EdgyNerd OK, I'm back for the next half an hour or so.
It seems that you're struggling a bit. Want help?
 
ok
 
6:29 PM
OK, let's see, we can get the divisibility table by using your function from above:
⎕←∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳10
 
@Adám
1 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0
1 1 0 1 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0
1 1 1 0 0 1 0 0 0 0
1 0 0 0 0 0 1 0 0 0
1 1 0 1 0 0 0 1 0 0
1 0 1 0 0 0 0 0 1 0
1 1 0 0 1 0 0 0 0 1
 
Now we can count the number of divisors for each row, simply by summing across:
⎕←+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳10
 
@Adám
1 2 2 3 2 4 2 4 3 4
 
And the primes are those that have exactly 2 divisors (1 and the number itself):
⎕←2=∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳10
 
@Adám
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
 
6:31 PM
Sorry.
⎕←2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳10
 
@Adám
0 1 1 0 1 0 1 0 0 0
 
oh right that makes a lot of sense
 
Actually, come to think of it, in my hurry, I forgot to give you the function to change a true/false list into a list of indices where true:
⍞←⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳10
 
@Adám 2 3 5 7
 
oh wow
 
6:34 PM
We already learned the monadic meaning of and (ceiling and floor). The dyadic meaning is max and min:
⍞←3⌈2 4
 
@Adám 3 4
 
⍞←3⌊2 4
 
@Adám 2 3
 
With this knowledge, you should actually be able to write an IsPrime that works for multiple arguments. Can you think of how?
@EdgyNerd If it isn't obvious, just let me know and I'll give you some pointers.
 
kind of but not really
 
6:37 PM
Want a hint?
 
yeah
 
Hint 1 (of 3, if you want more hints…): You can find the largest element of a list by inserting between all elements 3⌈1⌈4⌈1⌈5 or simply:
⍞←⌈/3 1 4 1 5
 
@Adám 5
 
oh I have to go for about 10-20 mins, I'll be back in a bit
also I have an idea now but I'll try it after I come back
 
OK, if I'm not here when you come back, feel free to play with it all, and I'll check in later.
 
7:17 PM
⍞←⍳/1 2 3
 
@EdgyNerd RANK ERROR
 
Hey I was wondering if someone could help me figure this out
how can I multiply a vector by each element of a list of lists?
⍞←{3,/⍵} 1 2 3 4 5
 
@frank  1 2 3  2 3 4  3 4 5
 
1 0 1ר{3,/⍵} 1 2 3 4 5 doesnt work, neither does 1 0 1∘.×{3,/⍵} 1 2 3 4 5
 
7:39 PM
@EdgyNerd I'm here from now on.
 
oh ok
 
@frank Can you type out by hand what you expect as a result?
@EdgyNerd Do you want another hint?
 
yeah
 
1 0 1 ×? {3,/⍵} 1 2 3 4 5 -> 1 0 3, 2 0 4, 3 0 5
 
@frank What is the input for that result?
 
7:41 PM
sorry, edited
 
@EdgyNerd You can find all the primes until the maximum of the argument, and then check if each of the argument is a member of the primes thus generated. Let me know if you need a hint on how to check for membership.
 
I'm kinda confused what you mean by 'is a member of'
oh wait no I get it
 
@frank OK, so think of how APL pairs up numbers when doing arithmetic. 1 2 3+30 40 50 gives 31 42 53. So you just need to treat 1 0 1 as a single number. You can do so by enclosing it to make it a scalar: ⊂1 0 1 is a scalar that contains 1 0 1:
 
@Adám actually how do I check for membership?
 
⎕←(⊂1 0 1)×3,/⍳5
 
7:45 PM
@Adám
┌─────┬─────┬─────┐
│1 0 3│2 0 4│3 0 5│
└─────┴─────┴─────┘
 
ah I see, thank you!
 
wait actually no don't tell me
I think I've got it
 
@frank Alternatively, you can create a "multiply by 1 0 1" function and apply it to each element:
 
actually no I haven't
 
⎕←1 0 1∘ר3,/⍳5
 
7:47 PM
@Adám
┌─────┬─────┬─────┐
│1 0 3│2 0 4│3 0 5│
└─────┴─────┴─────┘
 
@EdgyNerd OK, I'll start off with a hint:
⎕←3 4∘.=2 3 5 7
 
@Adám
0 1 0 0
0 0 0 0
 
@EdgyNerd Do you understand ^ ?
 
yeah I think so
⍞←{⍵{⍺=b}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊⍵}}13 14
 
@EdgyNerd      ∇{⍵{⍺=b}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊⍵}
 
7:49 PM
@EdgyNerd mismatched braces? Also, what is b?
 
⍞←{⍵{⍺=b}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊⍵}}}13 14
 
@EdgyNerd
 
oh yeah oops
⍞←{⍵{⍺=⍵}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊⍵}}}13 14
um
⍞←{⍵{⍺=⍵}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊⍵}}}13 14
wait no
I'm so confused
can you walk me through it
 
⎕←⌈/3 4∘.=2 3 5 7
 
@Adám
1 0
 
7:53 PM
⍞←⌈/13 14
 
@Adám 14
 
⍞←{⍵{⍺=⍵}{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊/⍵}}}13 14
 
@EdgyNerd
 
⍞←{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⌈/⍵}13 14
 
@Adám 2 3 5 7 11 13
 
7:55 PM
⍞←{⍵∘.{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊/⍵}}13 14
 
@EdgyNerd      ∇{⍵∘.{⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⍵}⌊/⍵}
 
⎕←{13 14∘.=⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⌈/⍵}13 14
 
@Adám
0 0 0 0 0 1
0 0 0 0 0 0
 
⎕←{⌈/⍵∘.=⍸2=+/∘.{{⍵=⌊⍵}⍺÷⍵}⍨⍳⌈/⍵}13 14
 
@Adám
1 0
 
7:56 PM
can you explain that to me?
I'm really confused
 
Don't worry, we'll sort it out until it is clear.
@Cxom Hello there. Interested in APL?
 

« first day (1055 days earlier)      last day (1600 days later) »