I came up with the following challenge and I don't know how to implement it in J.
Define a rank 2 verb f which operates on tables with elements from the set {0, 1, 2}. Example input:
]a =: 4 4 $ 1 0 1 1 2 2 1 1 1 2 0 1 2 0 2 2
1 0 1 1
2 2 1 1
1 2 0 1
2 0 2 2
Each element of the table besides the value has its default index given by i. . For the above example it is
i. 4 4
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
f should return list of pairs of indices (i, j) such that elements i-th and j-th are on the same diagonal and the value of i-th element is 1 and the value of j-th element is 2. The diagonals are given by
</. a
┌─┬───┬─────┬───────┬─────┬───┬─┐
│1│0 2│1 2 1│1 1 2 2│1 0 0│1 2│2│
└─┴───┴─────┴───────┴─────┴───┴─┘
The output for above example (the order of pairs in a list does not matter) is as follows
f a
8 5
2 5
6 12
3 12
6 9
3 9
11 14
Thanks,
Marcin