Forget Perl, this is serious write-only software engineering.
I mean, I'm a language polyglot, and I think these languages are probably great for multidimensional array processing. But for general purpose programming, not so much.
But cool hack.
I mean, I'm a language polyglot, and I think these languages are probably great for multidimensional array processing. But for general purpose programming, not so much.
But cool hack.
I have a new programmer- strong maths background, but no programming experience prior to K which she started about two weeks ago.
Today, she's working on taking strings that look like this:
y:"http://host/path/to.a.swf,http://host/path/to/b.swf"
and finding out if the url-fragments are "claimed" by any any other user in a database, AND if the current user claims any url-fragments. So she has a database like this: d:`f`u!(("adap.tv";"adap.tv";"btrll.com";"btrll.com";"cbs.com";"cbsinter…
l:?d`f
and in about thirty minutes of puzzling came up with this: |/#:'y ss/:l[&~|/d.f[&x=d.u]~/:\:l]
Since you don't know K I'll walk you through it: d.f[&x=d.u]~/:\:l
This returns a list of bitmaps, such as: (10000000000000000b;00000100000000000b)
What it's doing is taking all of the urls and indexing it by the where (&) address of each x (parameter to function: user id) is equal to the array of all of the users. That is, x=d.u returned: 01000001000000000000000000b and &x=d.u returned 1 7 (because the second and eighth element of that bitmap are ones). d.f[1 7] returns the second and eighth fragment.Then, she &~|/ which ors- the bitmaps (|/) together, finds their complement (~), and takes the where of (&) them, so in this case 0 5. l[0 5] then returns the strings in the master list.
Note this is the list of all of the url fragments owned by other users:
l[&~|/d.f[&x=d.u]~/:\:l]
In PHP you might try to write: $mine = array();
$theirs = array();
foreach($db as $row) {
if($row->u === $x) $mine[$row->f]=0;
else $thiers[$row->f]=0;
}
$list = array_diff(array_keys($thiers),array_keys($mine));
but there's a lot of syntax here, and a number of PHP function calls that a beginner might not be aware of. She's just using this: http://www.timestored.com/kdb-guides/files/kdb-cheat-sheet.pdf
So then on to y ss/: which basically does a `strpos()` of each of our urls against the list we're scanning (i.e. the thing that looks like "http://url,http://otherurl". She then counts each (#:') result, takes the max again (|/). This means if ANY of those match, return `1b` otherwise return `0b`.