Using the J language, I want to achieve a mapping of the counts of the elements of an array.
In particular, I want to enter a lowercase word with two different letters and return each pair of letters to the word along with counts of occurrences.
I need a verb that gives something like this in any J-structure that you think is appropriate:
For 'cocoa':
co 2
oc 1
oa 1
For a banana:
ba 1
an 2
na 2
For "milk":
mi 1
il 1
lk 1
For 'to':
to 1
(For single-letter words, such as 'a', the task is undefined and no attempt will be made.)
(The order is not important, since I have listed them.)
I can easily get consecutive pairs of letters in a word as a matrix or a list of fields:
2(] ;._3)'cocoa'
co
oc
co
oa
]
2(< ;._3)'cocoa'
ββββ¬βββ¬βββ¬βββ
βcoβocβcoβoaβ
ββββ΄βββ΄βββ΄βββ
But I need help to go from there to mapping pairs to numbers.
~. ~: . .
NuVoc "Loopless" , /(/\. /\) - , , / , u/y , , , y.
(NB. "" , Java Python, . SO J. J .)