I tested both Claude and Gemini with the same questions. One was simple: "What is the J code for calculating the average of a list of numbers?" This was followed by "How would I apply this code to a matrix of numbers to get the average of each column?".
Both got the first one with the expected standard J expression, which is not surprising because this may be the most common J expression floating around the web. On the second, Claude was better than Gemini which seemed confused by applying the expression on rank 1 for columns. However, Claude started this way, then corrected itself.
The second question was more involved but it was something I solved years ago in APL: "In J, if I have two 2-column tables of integers where the first column is the start of an interval and the second column is the end of an interval, how would I produce a matrix showing how much each interval in the first table overlaps with each interval in the second table? Bonus points if, for intervals with no overlap, we get a negative number showing the shortest gap between the two intervals."
Gemini basically failed and Claude did OK but was tripped up by the assumption that the start of an interval is always less than the end of an interval. This tripped me up too when I first wrote this but I subsequently accounted for it by cleaning my input data.
The Claude code basically worked, sans the tricky case, but was not terribly idiomatic and exhibited the same sort of false start as in the follow up to the first question. Here is what it ended up with after it cleaned up its original try:
Final Working Version
j
A =: 3 2 $ 1 5 3 8 10 15
B =: 3 2 $ 2 6 4 7 12 20
NB. Overlap of two intervals (2-element vectors): min(ends) - max(starts)
NB. Positive = overlap amount, negative = gap
ov =: 4 : '(<./ (1{x),(1{y)) - (>./ (0{x),(0{y))'
NB. Outer table: every row of A against every row of B
result =: A ov"1 1/ B
I will leave my version as an exercise for the reader. Here was my test input with a couple of tricky intervals that end before they start:
A=. 1 2,2 3,1 5,0 _1,4 6,:9 3
B=. 0 10,5 6,3 1,2 3,:_3 _1
Regards,
Devon