« first day (2151 days earlier)      last day (511 days later) » 

5:12 AM
I don't think I can make it in Day 16.
 
 
4 hours later…
8:49 AM
@LdBeth yeah, i'm gonna wait for some fast answers to come up before attempting
 
 
4 hours later…
1:00 PM
Welcome to APL Quest 2017-6! Today's quest is k-mers:
> Write a dfn that takes a character vector as its right argument and k (the substring length) as its left argument and returns a vector of the k-mers of the original string.
Now, the core solution is very easy. The real problem here is handling the edge cases where k is larger than the length of the vector.
 
{⍺>≢⍵:⍬ ⋄ ⍺,/⍵}
or is that cheating?
 
No, not at all.
However, what can you say about the structure of the result?
 
list of vectors
 
Right, but isn't that.
 
⊂⍬
 
1:03 PM
That's a scalar of vectors.
 
ah yes
 
Also, what can you say about those inner vectors?
 
That they all have shape ⍺
no sorry
 
That's correct.
 
shape is 1
 
1:05 PM
Aha! So even if you do 0⍴⊂⍬ then that isn't quite right, because has length 0, not
 
yes
 
Also, what of what type are those inner vectors?
 
string/vector of characters
 
Right, and is a numeric vector, so even if you do 0⍴⊂⍺⍴⍬ it isn't quite right either.
 
⎕ucs 0 ?
 
1:09 PM
That would work.
But you can actually use any character, because the outer array is empty, so there'll only be the prototype, and that's always made of spaces for character arrays and zeros for numeric arrays.
0⍴⊂⍺⍴'' will even do.
 
and how about just ''
 
That's what I wrote. Font issues?
 
ok!
 
That said, why not make the function more generally applicable? Let's allow numeric "DNA" too? How might we get a prototype that matches the argument type?
 
using ⍕ for each input
ah not does not work
Do you also mean mixed input?
 
1:14 PM
No, there's no way to handle that. Assume homogeneous data.
But 5 f 'abc' should give 0⍴⊂5⍴'' and 5 f 1 2 3 should give 0⍴⊂5⍴⍬
In other words, how can we get '' from any given character vector and from any given numeric vector?
 
There's probably a better way then checking wether the input is numeric or not.
 
Indeed. Do it as a function of the given array.
 
So also not ⎕VFI. Still thinking
 
Look at these two together, and you should see some commonality:
'abc'
''
You could call the second a ____ version of the first.
 
with ↓
4↓⍳3 and 4↓ '123'
 
1:22 PM
Sure, that could work. But what number would you put on the left?
 
≢⍵
 
Sure. So now we have 0⍴⊂⍺⍴(≢⍵)↓⍵
But wait a minute! the ⍺⍴ extends to the length anyway, so why do we need to adjust the length of
You might think that it is to get rid of the actual characters, but 0⍴⊂ will replace them all with spaces anyway, so no need!
 
I've investigated this issue a bit more and have found that
a←1500⌶,⊂1 1
(⊂4 4)~a
a,←,⊂5 5
Gets me to the same error
 
just to get the right type from the input.
@Adám yes indeed
 
Putting it all together, we get {⍺>≢⍵:0⍴⊂⍺⍴⍵ ⋄ ⍺,/⍵} which is a very nice solution.
 
1:27 PM
nice lesson in type and shape
 
[Sorry if that got broken up .. delivery man startled me !]
 
It is actually possible to do this without a branch (guard). I'll speak about that in the follow-up video.
 
extending the list and removing them at the end?
 
That's a possibility, but better to only extend if needed.
There's also a minor thing that if the left argument is 1 then we'll do ,/ over length-one subvectors, which gives us a simple scalar, so the result becomes a vector of scalars (i.e. a simple vector) rather than a vector of vectors. But I'll leave that alone.
 
:)
 
An additional task to extend the next excercise would be nice. No hurry.
 

« first day (2151 days earlier)      last day (511 days later) »