« first day (558 days earlier)      last day (2079 days later) » 

9:31 AM
hello
 
@MuhammadSalman Welcome back! Remind me again what your background is.
 
studying engineering/maths. I know a couple of programming languages
 
@MuhammadSalman Right. OK, maybe we'll explore finding primes in a matrix-oriented (but unfortunately inefficient) manner?
 
@A
@Adám whatever u choose.
 
@MuhammadSalman OK, let's start by getting the natural numbers. For that we use the index generator, (it is a Greek letter iota for indices):
⎕←⍳25
 
9:36 AM
@Adám
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
 
hold on so iota(number) will give all natural number b4 the number ?
 
@MuhammadSalman Normally, all natural numbers from 1 until that number, as long as you use 1-based indexing. If you switch to 0-based indexing, it will give from 0 to the number minus one.
 
⎕←⍳120
 
@MuhammadSalman
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
 
Okay. the site u gave(this) is still useful :)
@Adám so by default it is 1-based indexing ?
 
9:40 AM
@MuhammadSalman Dyalog APL is. Some APLs have 0 as default (or only) choice.
Strictly speaking, it will give all indices in an array of the given dimensions, so a vector (i.e. a 1D array) with length N has the valid indices 1,2,3,…,N-1,N.
A matrix with dimensions 3 4, i.e. 3 rows and 4 columns has the following valid indices:
⎕←⍳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│
└───┴───┴───┴───┘
 
Cool, so can take 2 params ? ⍳ a b a is for row, b is for col
 
@MuhammadSalman It can take any valid dimensions:
⎕←2 3 4
 
@Adám
2 3 4
 
⎕←⍳2 3 4
 
9:43 AM
@Adám
┌─────┬─────┬─────┬─────┐
│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 3 1│1 3 2│1 3 3│1 3 4│
└─────┴─────┴─────┴─────┘
┌─────┬─────┬─────┬─────┐
│2 1 1│2 1 2│2 1 3│2 1 4│
├─────┼─────┼─────┼─────┤
│2 2 1│2 2 2│2 2 3│2 2 4│
├─────┼─────┼─────┼─────┤
│2 3 1│2 3 2│2 3 3│2 3 4│
└─────┴─────┴─────┴─────┘
 
That's two layers, three rows, four columns.
 
WOW.
⎕←⍳2 3 4 5
 
@MuhammadSalman
┌───────┬───────┬───────┬───────┬───────┐
│1 1 1 1│1 1 1 2│1 1 1 3│1 1 1 4│1 1 1 5│
├───────┼───────┼───────┼───────┼───────┤
│1 1 2 1│1 1 2 2│1 1 2 3│1 1 2 4│1 1 2 5│
├───────┼───────┼───────┼───────┼───────┤
│1 1 3 1│1 1 3 2│1 1 3 3│1 1 3 4│1 1 3 5│
├───────┼───────┼───────┼───────┼───────┤
│1 1 4 1│1 1 4 2│1 1 4 3│1 1 4 4│1 1 4 5│
└───────┴───────┴───────┴───────┴───────┘
┌───────┬───────┬───────┬───────┬───────┐
│1 2 1 1│1 2 1 2│1 2 1 3│1 2 1 4│1 2 1 5│
├───────┼───────┼───────┼───────┼───────┤
 
Well, it is called the indices or the index generator for a reason.
@MuhammadSalman That's a 4D array of two blocks, three layers, four rows, five columns.
And you can keep going well beyond what your mind can think about!
 
Lemee try something.
 
9:45 AM
@MuhammadSalman You may want to keep your dimensions short…
 
⎕←⍳2 3 4 5 6 7 8 9 10 11
 
@MuhammadSalman
WS FULL
 
let's see if I broke it
 
@MuhammadSalman You didn't. It just responded that it was not allocated enough memory for that.
(The result would contain 400 million numbers.)
 
Oh, ok. so what's the max b4 memory allocation error occurs ?
 
9:48 AM
@MuhammadSalman Depends on the setup. WS stands for WorkSpace. Let's ask how much TIO allocates by default:
⎕←⎕WA
 
@Adám
133223416
 
⎕←⍳2 3 4 5 6 7 for me works. but anything above that is WS error
 
Workspace Available is about 130 million bytes. No wonder we can't fit 400 million numbers!
 
oh, well that explains that.
⎕←⍳2 3 4 5 6 7
 
@MuhammadSalman
┌───────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┐
│1 1 1 1 1 1│1 1 1 1 1 2│1 1 1 1 1 3│1 1 1 1 1 4│1 1 1 1 1 5│1 1 1 1 1 6│1 1 1 1 1 7│
├───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│1 1 1 1 2 1│1 1 1 1 2 2│1 1 1 1 2 3│1 1 1 1 2 4│1 1 1 1 2 5│1 1 1 1 2 6│1 1 1 1 2 7│
├───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│1 1 1 1 3 1│1 1 1 1 3 2│1 1 1 1 3 3│1 1 1 1 3 4│1 1 1 1 3 5│1 1 1 1 3 6│1 1 1 1 3 7│
 
9:51 AM
@MuhammadSalman However, this is only because TIO has a low limit. On my local machine I have set the maximum workspace size to 2G.
@MuhammadSalman TIO also limits the amount of output you may generate. And really, do you want to print 30000 numbers?
 
@Adám not really, I guess
 
OK, we want to get some primes, so we're not interested in the first number. Let's drop one element from the left with the drop function:
⎕←1↓⍳25
 
@Adám
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 
so ↓ is the drop character ?
 
@MuhammadSalman Yes, and you can use a negative number to instead drop from the back:
⎕←¯4↓'APL is fun'
 
9:54 AM
@Adám
APL is
 
⎕←-10 ↓ ⍳ 20
 
@MuhammadSalman
¯11 ¯12 ¯13 ¯14 ¯15 ¯16 ¯17 ¯18 ¯19 ¯20
 
what happened here ?
 
@MuhammadSalman Remember that APL is strictly right-associative. so - is applied after 10↓⍳20.
You need the negative symbol ¯ (high minus).
 
⎕←¯10 ↓ ⍳ 20
 
9:56 AM
@MuhammadSalman
1 2 3 4 5 6 7 8 9 10
 
Let's have a look at | which is the division remainder function:
 
same as % ?
 
@MuhammadSalman Almost. The arguments are reversed compared to most languages:
⎕←2 4 5 6|10
 
@Adám
0 2 0 4
 
so a | b is basically b % a ?
 
9:59 AM
@MuhammadSalman Yes.
However, we need to generate a table of division remainders, so we need the outer product operator ∘. For example, we can generate a multiplication table with:
⎕←1 2 3 4∘.×1 2 3 4
 
@Adám
1 2  3  4
2 4  6  8
3 6  9 12
4 8 12 16
 
Whenever we need to apply a function using the same array as left and right argument, we can use the selfie operator (yes, that looks like a face selfie):
⎕←∘.×⍨1 2 3 4
 
@Adám
1 2  3  4
2 4  6  8
3 6  9 12
4 8 12 16
 
what happende here >
so selfie op makes it so that left = right ?
 
@MuhammadSalman Yes. E.g. you can make a "double" function as +⍨ (plus selfie):
⎕←+⍨3 4 5
 
10:02 AM
@Adám
6 8 10
 
And a "square" function" as ×⍨ (multiplication selfie):
 
this is doing : 3 + 3 , 4 + 4 , 5 + 5 ?
 
⎕←×⍨3 4 5
@MuhammadSalman Yes.
 
@Adám
9 16 25
 
COOL
⎕←×⍨10
 
10:03 AM
Now we can make a division-remainder table:
 
@MuhammadSalman
100
 
this gives square of 10. correct
 
⎕←∘.|⍨1↓⍳10
 
@Adám
0 1 0 1 0 1 0 1 0
2 0 1 2 0 1 2 0 1
2 3 0 1 2 3 0 1 2
2 3 4 0 1 2 3 4 0
2 3 4 5 0 1 2 3 4
2 3 4 5 6 0 1 2 3
2 3 4 5 6 7 0 1 2
2 3 4 5 6 7 8 0 1
2 3 4 5 6 7 8 9 0
 
what ?
 
10:05 AM
@MuhammadSalman It is as if the table has the headings 2,3,4,5,…10 along the top, and going down the left side.
And every number inside is left|top.
 
ah, so why drop the first ?
what is 1↓ doing here
 
@MuhammadSalman We didn't have to, but the the first row and column of the remainder table are boring:
⎕←∘.|⍨⍳10
 
@Adám
0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 0 1 0
1 2 0 1 2 0 1 2 0 1
1 2 3 0 1 2 3 0 1 2
1 2 3 4 0 1 2 3 4 0
1 2 3 4 5 0 1 2 3 4
1 2 3 4 5 6 0 1 2 3
1 2 3 4 5 6 7 0 1 2
1 2 3 4 5 6 7 8 0 1
1 2 3 4 5 6 7 8 9 0
 
division by 1 right ?
 
@MuhammadSalman Yes, and remainder when 1 is divided by N. But you know what, let's use this last table anyway!
 
10:10 AM
okay
 
Remember that a prime number is a natural number which has exactly two divisors, no more and no less.
 
We're not really interested in what the division remainders actually are; we just what to note when they are 0.
So conveniently, = is APL is not assignment (which is ) but just an element-by-element comparison, returning 0 for false and 1 for true:
⎕←2 3 2=2
 
@Adám
1 0 1
 
(This is actually an implied Iverson bracket from traditional mathematics. Indeed, Iverson was the creator of APL.)
Now we can compare 0 to our remainder table:
⎕←0=∘.|⍨⍳10
 
10:13 AM
⎕←2 3
 
@Adám
1 1 1 1 1 1 1 1 1 1
0 1 0 1 0 1 0 1 0 1
0 0 1 0 0 1 0 0 1 0
0 0 0 1 0 0 0 1 0 0
0 0 0 0 1 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
@MuhammadSalman
2 3
 
2 = 2 is doing what ?
 
@MuhammadSalman Checking whether it is true that 2=2. Which it is. So APL gives 1.
 
oh, my bad. I remember u already told me
 
No problem.
And now you can already spot the primes. They are the ones that have exactly two 1s in their respective columns.
So lets sum the columns to get the number of divisors. We can sum columns using the vertical-reduction operator :
⎕←+⌿0=∘.|⍨⍳10
 
10:16 AM
@Adám
1 2 2 3 2 4 2 4 3 4
 
APL has vertical reduction ?
 
@MuhammadSalman Yes. / is horizontal (literally "last-axis") reduction, and is vertical (literally, "first-axis") reduction.
 
so numbers which equal 2 are primes ?
 
@MuhammadSalman Yes, exactly. So now we need to compare to 2:
⎕←2=+⌿0=∘.|⍨⍳10
 
@Adám
0 1 1 0 1 0 1 0 0 0
 
10:18 AM
Now we have a Boolean list indicating our primes.
Finally, we can use the where function to get us the indices of the "true"s:
 
⎕←⍸2=+⌿0=∘.|⍨⍳10
 
@Adám
2 3 5 7
 
what supposed to be ?
 
@MuhammadSalman It is a Greek iota with an underbar.
 
10:20 AM
seriously ?
 
@MuhammadSalman Yes. Does it not render right for you?
 
it gives indicies of number that fulfill the condition ?
right?
 
@MuhammadSalman Yes. Well, it gives the indices of all 1s in a Boolean array.
 
Works on multi-dimensional arrays too. E.g. we can find the indices of all the divisors from our Boolean table above:
⎕←0=∘.|⍨⍳10
 
10:22 AM
@Adám
1 1 1 1 1 1 1 1 1 1
0 1 0 1 0 1 0 1 0 1
0 0 1 0 0 1 0 0 1 0
0 0 0 1 0 0 0 1 0 0
0 0 0 0 1 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
 
⎕←⍸0=∘.|⍨⍳10
 
@Adám
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬────┬───┬───┬───┬───┬────┬───┬───┬───┬───┬───┬───┬────┬───┬───┬───┬───┬─────┐
│1 1│1 2│1 3│1 4│1 5│1 6│1 7│1 8│1 9│1 10│2 2│2 4│2 6│2 8│2 10│3 3│3 6│3 9│4 4│4 8│5 5│5 10│6 6│7 7│8 8│9 9│10 10│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴────┴───┴───┴───┴───┴────┴───┴───┴───┴───┴───┴───┴────┴───┴───┴───┴───┴─────┘
 
cool.
u guys should have named it AML (a mathematical language) instead of APL.
 
@MuhammadSalman Originally, it was just Iverson's mathematical notation or Iverson Notation and it was intended to be a more powerful and consistent replacement for traditional mathematical notation. Then Iverson wrote a book about theoretically using such a formalised language to control computers. He called the book A Programming Language. When it was finally implemented, they looked for a name, and someone suggested APL until they could find something better…
 
how old is this language ?
 
10:27 AM
@MuhammadSalman The book appeared in '62.
 
so 40+ years and they couldn't find a better name for this language ? that
.. wow
well, anyway APL is quite cool.
 
Well, it became well-known as APL, so there was no reason to change it. Then APL later got a bad name (at a time when the special characters were problematic), so Dyadic Systems tried pushing the name Dyalog instead of APL. But now (with Unicode) APL is slowly gaining ground again, and APL is a perfectly adequate name compared to many other programming languages' names.
@MuhammadSalman Want to see a variation on what we just did?
 
I guess it works.
@Adám sure, that'd be great
 
OK. If you think about it, a prime is a number that does not occur in the multiplication table:
⎕←∘.×⍨⍳25
 
@Adám
 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
 2  4  6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46  48  50
 3  6  9  12  15  18  21  24  27  30  33  36  39  42  45  48  51  54  57  60  63  66  69  72  75
 4  8 12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80  84  88  92  96 100
 5 10 15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95 100 105 110 115 120 125
 6 12 18  24  30  36  42  48  54  60  66  72  78  84  90  96 102 108 114 120 126 132 138 144 150
 
10:36 AM
(other than in the topmost row and leftmost column, of course)
 
APL comes with a handful of set functions, e.g. ~ for set subtraction:
⎕←1 2 3 4 5 6~2 5
 
@Adám
1 3 4 6
 
Btw, ~ (known as without) allows any array to be treated like a set, so we can "set subtract" a matrix from a vector.
 
10:39 AM
That is, if we take all the natural numbers (except for 1) and remove all the numbers in the multiplication table (beginning with 2×2), only the primes remain:
⎕←⍳15
 
@Adám
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
Let's remove the first one:
⎕←1↓⍳15
 
@Adám
2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
And now we assign this to N so we can reuse it (as an alternative to using ), e.g.:
⎕←N∘.×N←1↓⍳15
 
@Adám
 4  6  8 10 12  14  16  18  20  22  24  26  28  30
 6  9 12 15 18  21  24  27  30  33  36  39  42  45
 8 12 16 20 24  28  32  36  40  44  48  52  56  60
10 15 20 25 30  35  40  45  50  55  60  65  70  75
12 18 24 30 36  42  48  54  60  66  72  78  84  90
14 21 28 35 42  49  56  63  70  77  84  91  98 105
16 24 32 40 48  56  64  72  80  88  96 104 112 120
18 27 36 45 54  63  72  81  90  99 108 117 126 135
20 30 40 50 60  70  80  90 100 110 120 130 140 150
22 33 44 55 66  77  88  99 110 121 132 143 154 165
 
10:41 AM
hold on.
 
@MuhammadSalman Yes?
 
N←1↓⍳15 (this part assignes 1↓⍳15 to N)
u used N before it was defined ?
nvm, I forgot right to left
 
@MuhammadSalman Yes. And assignments also have a "pass-through" value which is whatever is on the right of the .
So these are the numbers we need to remove. Let's remove them from N:
⎕←N~N∘.×N←1↓⍳15
 
@Adám
2 3 5 7 11 13
 
nice.
this leaves us with all the primes
 
10:45 AM
@MuhammadSalman Yes. Now let's look at how we make that into a user defined function that we can save for later.
 
apl has functions ?
 
The easiest type of user defined APL function (fn) to use is the one-liner "dfn" (direct function). You can create one with a simple assignment. The body of the function is enclosed in curly braces: primes←{body of function}
@MuhammadSalman You mean user-defined ones? Yes, of course. It is a programming language :-)
 
primes ← { N ~ N ∘. × N ← 1 ↓ ⍳ 15 }
⎕← primes
 
@MuhammadSalman
VALUE ERROR
 
@MuhammadSalman That will work, but it will always generate the primes until 15.
@MuhammadSalman Oh, the bot doesn't look at such lines. Here:
⎕←primes ← { N ~ N ∘. × N ← 1 ↓ ⍳ 15 } ⋄ ⎕←primes 'dummy'
 
10:49 AM
@Adám
{N~N∘.×N←1↓⍳15}
2 3 5 7 11 13
 
don't get what happened ⋄ ⎕←primes 'dummy' ?
 
is the statement separator. The bot only accepts single self-contained lines.
@MuhammadSalman A dfn must be supplied with at least one argument, even if that argument isn't used. So I gave it a dummy argument.
 
is basically like ;
?
 
@MuhammadSalman Yes, exactly, except it isn't required to terminate statements.
Now in a dfn, the right argument is designated because omega is the rightmost letter of the Greek alphabet.
So we can create a primes function which takes an argument (the upper limit) as primes←{N~N∘.×N←1↓⍳⍵}
Also, the bot recognises lines beginning with so you can have assignments without echoing:
 
so when I want to call primes←{N~N∘.×N←1↓⍳⍵} i call it like primes 15
 
10:53 AM
⋄ primes←{N~N∘.×N←1↓⍳⍵} ⋄ primes 25
Uh, or at least I thought the bot would understand. It just got an overhaul, so I may have messed it up. One minute.
#tio alias view
 
@Adám
Command Aliases:
]help -> #TIO apl {0::⎕←⊃⎕DM⋄⎕←⎕SE.UCMD'help %args% -url'}(⎕NS⍬).(enableSALT⊣⎕CY'salt')
⋄ -> #TIO apl {0::⎕←⊃⎕DM⋄%args%}(⎕NS⍬).(⎕SE.UCMD'box on -f=on -t=tree'⊣enableSALT⊣⎕CY'salt')
⍞← -> #TIO do apl-dyalog {0::⎕←⊃⎕DM⋄⎕←%args%}⍬
] -> #TIO apl {0::⎕←⊃⎕DM⋄⎕←⎕SE.UCMD'%args%'}(⎕NS⍬).(⎕SE.UCMD'box on -f=on -t=tree'⊣enableSALT⊣⎕CY'salt')
⎕← -> #tio apl {0::⎕←⊃⎕DM⋄⎕←%args%}(⎕NS⍬).(⎕SE.UCMD'box on -f=on -t=tree'⊣enableSALT⊣⎕CY'salt')

Language Aliases:
apl-dyalog -> [apl]

Message Aliases:
 
Oh, my fault!
⋄ primes←{N~N∘.×N←1↓⍳⍵} ⋄ ⎕←primes 25
 
@Adám
2 3 5 7 11 13 17 19 23
 
In an interactive session, you wouldn't need the leading or the ⎕←, but the way the bot uses TIO requires it.
 
10:56 AM
ok
 
@MuhammadSalman In fact, you don't even need to name your functions. In-line anonymous functions work fine:
⎕←{N~N∘.×N←1↓⍳⍵}30
 
@Adám
2 3 5 7 11 13 17 19 23 29
 
nice! so arguments go after braces
for lambda function
 
@MuhammadSalman The right argument does. But just like some built-in (so called primitive) APL functions are in-fix, so too can you create infix user defined functions. The left argument (though optional) is designated because alpha is the leftmost letter of the Greek alphabet.
 
why am I getting this : ` ⎕PW←32767
'#'⎕NS⎕FIX'file:///home/runner/.bin.tio.dyalog'`
 
11:00 AM
@MuhammadSalman Uh, where?
 
primes ← { N ~ N ∘. × N ← 1 ↓ ⍳ ⍵ }
⎕ ← primes 15
 
@MuhammadSalman On TIO?
 
@MuhammadSalman Try using the Unicode version instead of the Classic one.
 
im using dylog ?
worked. thx
 
11:02 AM
Remember our first prime finder expression? ⍸2=+⌿0=∘.|⍨⍳30
 
We can use it to explore divisor counts by making it into a lambda taking the number of divisors as left argument.
⎕←2{⍸⍺=+⌿0=∘.|⍨⍳⍵}30
 
@Adám
2 3 5 7 11 13 17 19 23 29
 
Notice the use of and for the arguments.
Which numbers have exactly four divisors?
⎕←4{⍸⍺=+⌿0=∘.|⍨⍳⍵}30
 
@Adám
6 8 10 14 15 21 22 26 27
 
11:05 AM
hold on so ⍺ is written on left side while ⍵ on right ?
nice.
 
@MuhammadSalman Yes. The dfn (lambda) is now infix, just like = and | etc.
 
Of course, you can always use a list of argument if you prefer that:
⎕←{⍸⍵[1]=+⌿0=∘.|⍨⍳⍵[2]}4 30
 
@Adám
6 8 10 14 15 21 22 26 27
 
11:08 AM
But infix is usually neater and more versatile, and you can always convert your infix function to a prefix one by using reduction (/ or ):
⎕←{⍸⍺=+⌿0=∘.|⍨⍳⍵}/4 30
 
@Adám
┌────────────────────────┐
│6 8 10 14 15 21 22 26 27│
└────────────────────────┘
 
The reason for the box is that / must reduce the rank of the argument from a vector (1D) to a scalar (0D), so it encapsulates the result in a scalar.
 
What's the filename of Dyalog APL files?
*file extension
 
@BetaDecay You may use any, but by default, human-readable text files are .dyalog and binary containers ("workspaces") are .dws. There are a couple of others too, but they are pretty rare.
@MuhammadSalman Want more?
 
@Adám thnx 4 lesson. If u don't mind (and have time) we can continue tomorrow ? I have 2 go somewhere
 
11:13 AM
@Adám Ok thanks1
!
 
@MuhammadSalman No problem at all. I have things to do to. Just ping me!
 
ok. thnx :)
 
 
2 hours later…
12:46 PM
Continuing our exploration of @dyalogapl with Pattern Matching in Dyalog APL: https://ac1235.github.io/pmapl.html
 
 
5 hours later…
5:30 PM
Hey @Adám, any obvious golfs I can do to {(⍵×.012)+|10÷⍨-/⍺[⍋⍺]} ?
 
@J.Sallé 10÷⍨.1×
 
>.> I knew there was at least one obvoius golf
 
@J.Sallé How many elements does have?
 
@Adám anywhere from 2 to n
The test case hass an with 7 elements
 
@J.Sallé And you use the alternating sum of the sorted ? Interesting.
 
5:33 PM
@Adám Yes, it's for this challenge
I think I can use some form of ∘.<op> but I'm not entirely sure
Also not sure if that would save any bytes tbh
 
@J.Sallé I'm not sure your formula is right. The walked-through example gives 120, but OP has 140.
 
@Adám I'll take a look at that. The one I tested with was correct, so I didn't bother looking further
@Adám yep, you're right. It only returns right for one test case D:
 
@J.Sallé I think I have a 20 byte solution
 
@Adám I'm trying an approach using ∘.> now to compare with itself
Not quite sure if that's gonna work but I'm working on it
 
@J.Sallé I don't understand why you need that. You just need to check pairwise difference, no?
 
5:46 PM
@Adám that's what I was trying to do actually
 
@J.Sallé Pairwise is 2 fn/ list
 
@Adám ...I should've known that >.>
Well actually I did know that, I just derp'd and didn't think of using it
 
6:11 PM
@Adám got 27 bytes because I can't figure out how to "sum the differences" so to speak
 
@J.Sallé What have you got?
 
@Adám Had to assign (2-/⍺) to a vector so I could work it out: {(⍵×.012)+¯.1×+/f×1>f←2-/⍺}
 
@J.Sallé Why 1> instead of 0≥?
 
@Adám no idea. Also, not sure what the difference would be >.>
 
@J.Sallé None, afaict. And using 0≥ should hint you at a better solution…
 
6:17 PM
@Adám Okay, I'll try that
 
@J.Sallé Btw, I really enjoy seeing that you're using arithmetic to "filter". This is one of Iverson's most famous ideas — an idea that Knuth argued should become mainstream.
 
@Adám Yeah, I was actually taught to do this by a high school teacher
 
6:31 PM
@Adám question: Shouldn't {0(≥/⊢)(2-/⍺)} translate into (0≥(2-/⍺)/(2-/⍺))? According to the A(f g h)B thing?
 
@J.Sallé Yes, it should, but only if / was always a function. Unfortunately, it prefers being an operator, and so it parses as ≥/0⊢(2-/⍺), i.e. ≥/2-/⍺.
 
@Adám ah, I see. I'll see if I can work around that
 
@J.Sallé Should I reveal that part of my solution?
 
@Adám sure
I'll try to figure it out and if I don't I'll look at it
 
@J.Sallé Use 0⌈ to null out the positive terms.
 
6:48 PM
@Adám Aaaaaaaaaaah yes! I never remember that dyadic ⌈⌊ are a thing
Still got 22 bytes though
It's the friggin' parens I tell ya
{+/(.012×⍵),0⌈¯.1×2-/⍺}
 
@J.Sallé Yup, pretty much what I had: .1×(.12×⊣)-1⊥0⌊2-/⊢
 
@Adám not the parens then, the brackets! What a bamboozle
I think I'll post the Dfn though
 
@J.Sallé You could post .1×(.12×⊣)-1⊥0⌊2-/⊢ as competing entry and also show the equivalent dfn {.1×(.12×⍺)-1⊥0⌊2-/⍵} or {.1×(.12×⍺)-+/0⌊2-/⍵}
 
@Adám found a problem with (I assume both) our answers though
One of the test cases actually has a 1 element I hadn't noticed before
Also, it's .012, not .12 >.>
I managed a (very, very iffy) fix: {+/(.012×⍺),0⌈¯.1×2-/({(≢⍵)>1:⍵⋄⍵,⍵}⍵)} (switching my ⍵ and ⍺ btw)
 
7:08 PM
@J.Sallé No, I factored out the 0.1×
 
@Adám ah, I see
Hadn't noticed that
 
7:21 PM
@J.Sallé While I'd argue such input is meaningless, you can fix it with {.1×(.12×⍺)-+/0⌈2-/⍵,0}
 
@Adám yeah I was thinking the same thing. I actually didn't know whether putting a 0 at the end would make a difference but yeah, it doesn't because it'll get ignored either way
 
7:35 PM
@J.Sallé Btw, save 2 by going tradfn with s replacing and .
 
@Adám Hacks!
 
ngn
7:53 PM
@Adám maybe you can use a ⊥ for the multiplication-subtraction
(.12×⍺)- -> .12⊥⍺,-
@J.Sallé ^
 
@ngn Ah, that's cool. No idea how it works but I'll add it to my answer anyway >.>
 
ngn
@J.Sallé well, it's base 0.12, it multiplies the left "digit" (⍺) by 0.12, preserves the right "digit" (the -+/...), and adds them together
if there were more digits to the left, they would be multiplied by 0.12*2, 0.12*3, etc
 
@ngn aaaaaaah, that's a really neat trick
 
 
2 hours later…
9:38 PM
@ngn Add to ?
 

« first day (558 days earlier)      last day (2079 days later) »