Masking the Upper Triangle of a Correlation Matrix
Brindle & Co's analytics feed publishes one number per series it tracks on each trading day, and the set of series is not fixed -- one feed carries two of them, the next carries five -- so every file opens by naming its columns. The correlation grid built from them is a mirror: the a-against-b cell and the b-against-a cell always carry the same number, and the diagonal is a column compared with itself, which is 1 by definition. The report therefore prints each pair once, and its heading needs the count of pairs it is about to list.
Task: Print how many genuinely different column pairs there are.
Input
The first line names the columns this feed carries: labels separated by single spaces, all different, and there is at least one. The second line holds one integer n, the number of days, where 2 <= n <= 1000. Then come n lines, each holding one number per label, separated by single spaces and given in the same order as the labels.
Output
One line holding a whole number: how many pairs of different columns exist among the ones this feed carries. A column paired with itself does not count, and a pair counts once however it is written round. A feed carrying a single column therefore has no pairs at all.
Example:
Input:
a b c
3
1 2 3
4 5 6
7 8 9
Output:
3
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in