Two solutions designed by my esteemed colleague Marshall, master of speeding up APL. The formulas used are both in '70s APL, so they works in APL\360 on an IBM/360 mainframe. They are anonymous prefix functions taking a character matrix as argument.
N is not needed but may be supplied as optional (and ignored) left argument.
The first solution is O(n2)
A naive approach:
Try it online!
Processes* the large data set in about 4.5 ms. TIO takes about twice that.
} "dfn"; the argument is
'aeiou'∘.=⍵ equality 3D array with vowels along the first axis, words along the middle axis and characters along the last axis
∨/ OR-reduction along the last axis; this gives us a 5-row table with one column per word
i← store that in
i (for in)
∧⌿ AND-reduction along the first axis; this gives us a mask of words that contain all vowels
+/ sum; count of words containing all vowels (we need to discount their "self-pairs")
)- subtract that from the following:
(⍉i)∧.∨i the Boolean matrix where the OR of corresponding masks is all-true.
, ravel (flatten)
+/ sum; this gives us the count of ordered pairs
0.5× halve; this gives us the count of unordered pairs
The second solution is O(n)
Breaks even with the above O(n2) solution at about 150 words of 10 evenly distributed characters. It requires 0-based indexing, and a pre-computed 32-by-32 Boolean vowel signature pairing table:
a←0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Processes* the large dataset in 0.09 ms. TIO's timing is too inconsistent to make any conclusions, but it is likely that it takes about twice the time here too.
* 64-bit Dyalog APL 17.0 on 2.6 Ghz i7-4720HQ