Skip to content

Commit d3bf175

Browse files
committed
add rank-sensitivity
1 parent 291bed8 commit d3bf175

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

2023-12-xx-rank-sensitivity.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Rank Sensitivity in K
3+
categories: [apljk]
4+
---
5+
6+
I wanted to try Advent of Code 23, and of course, it all went down an
7+
interesting rabbit hole even before starting.
8+
9+
One way I found to get data into a program (like __DATA__ in perl) was a snippet in discord:
10+
11+
```
12+
/
13+
2,2,2
14+
1,2,2
15+
3,2,2
16+
2,1,2
17+
\
18+
19+
data:{x:0:`argv 1; 1_(x?,"\\")#x}[]
20+
data
21+
```
22+
23+
and when trying to figure out why tf it worked....
24+
25+
26+
# Rank sensitivity
27+
28+
The `(x?,"\\")#x` part will do a find (`?`) on the `argv 1`, which in
29+
[ngn/k site](https://ngn.codeberg.page/k) gets all the lines of the
30+
program.
31+
32+
I thought `find` was right-atomic, and in oK it is, but in ngnk it is not.
33+
34+
```
35+
rgrau: I'm trying to understand find ? in ngnk. in some cases it feels right atomic (like oK does),
36+
but some other cases it takes the full right argument to do the search, or some cases it seems it only goes down "1 level".
37+
38+
"one"?"two" / 0N 0N 0 . right atomic?
39+
("one";"two")?"two" / 1 . takes full right arg. ok gives 0N 0N 0N
40+
("one";"two")?("two"; "one"; "three") / 1 0 0N . 1 level down?
41+
42+
It's very DWIM but it's indistinguishable from magic. Any trick to fit this in my brain?
43+
44+
chrispsn: This is ‘rank sensitivity’
45+
chrispsn: See https://matrix.to/#/!laJBzNwLcAOMAbAEeQ%3Amatrix.org/%242AMsFKfIBmSk2-opKjzgZj6tXLQdyEfQpRZoSCUhTvM
46+
chrispsn: The difference in rank between x and y determines what find outputs
47+
rgrau: ...magic... 🙂 . thanks!
48+
```
49+
50+
And that lead to:
51+
52+
https://code.kx.com/q/ref/find/#type-specific and
53+
https://news.ycombinator.com/item?id=27850272, which seem to indicate
54+
that `find` will drill down `y` until it looks like that's what you
55+
want to search for. Extremely DWIM.
56+
57+
58+
Back to the initial code, so, `(x?,"\\")#x` will do a reshape of x
59+
cutting it at the position where Find finds "\\". At first I didn't
60+
get why the Enlist of "\\" was needed, but if we look at `argv 1` we
61+
see that single character lines are `,"a"` rather than just `"a"`,
62+
because a single char is not really a list (or something).
63+
64+
Anyway, now that it's clear how we read that csv, we could convert it
65+
to a real 3x3 array with regular k, with
66+
67+
```
68+
`I$''","\'data
69+
/ or
70+
.''","\'data
71+
```

0 commit comments

Comments
 (0)