Getting the average of a list (e.g [2,6,7]
)
- Get the length of the list:
[2,6,7] -> 3
- Sum the numbers in the list:
2 + 6 + 7 = 15
. - Divide the sum by their count:
15 / 3 = 5
.
You should compare the averages of two lists of positive integers N and M, by returning a value if N has a higher average, another value if M has a higher average, and another one in case of a tie.
I/O rules
All the standard Input and Output methods are allowed.
Input
You may take input as two separate lists, a nested list, or anything else you consider suitable for the task. Please specify the format.
Output
The values provided have to be distinct and must consist of at least one non-whitespace character. Also, they must be consistent between runs (a single value for N, a single value for M, a single value for Tie). Please specify those in your answer. The values can be non-empty Strings, Bool values, Integers, or anything you consider suitable.
Specs
The lists will not necessarily have equal length.
You are guaranteed that the lists are non-empty.
Test Cases
I chose the values N wins
, M wins
and Tie
, which are pretty much self-evident.
N, M -> Output (Averages) [7], [6] -> N wins (N has 7, M has 6 ) [4,5], [4,4] -> N wins (N has 4.5, M has 4) [2,3,4], [4,5,6] -> M wins (N has 3, M has 5) [4,1,3], [7,3,2,1,1,2] -> Tie (both have 2.666...) [100,390,1], [89,82,89] -> N wins (N has 163.666..., M has 86.666...) [92,892], [892,92] -> Tie (lists are basically identical) [10,182], [12,78,203,91] -> Tie (both have 96)
Default Loopholes apply. Explanations are encouraged! This is code-golf, so the shortest code in bytes wins!