35
4
The so-called Will Rogers phenomenon describes a way to tweak statistics by raising the average in two (multi)sets when one element is moved between the two sets. As a simple example, consider the two sets
A = {1, 2, 3}
B = {4, 5, 6}
Their arithmetic means are 2
and 5
, respectively. If we move the 4
to A
:
A = {1, 2, 3, 4}
B = {5, 6}
Now the averages are 2.5
and 5.5
, respectively, so both averages have been raised through a simple regrouping.
As another example, consider
A = {3, 4, 5, 6} --> A = {3, 5, 6}
B = {2, 3, 4, 5} --> B = {2, 3, 4, 4, 5}
On the other hand, it's not possible to raise both averages for the sets
A = {1, 5, 9}
B = {4, 5, 7, 8}
The Challenge
Given two lists of non-negative integers, determine whether it is possible to raise both averages by moving a single integer from one list to the other.
The average of an empty list is not defined, so if one of the lists contains only one element, this element cannot be moved.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
Input may be taken in any convenient string or list format.
You must not assume that the elements in each list are unique, nor that they are sorted. You may assume that both lists contain at least one element.
Output should be truthy if both averages can be raised by moving a single integer and falsy otherwise.
This is code golf, so the shortest answer (in bytes) wins.
Test Cases
Truthy:
[1], [2, 3]
[1, 2, 3], [4, 5, 6]
[3, 4, 5, 6], [2, 3, 4, 5]
[6, 5, 9, 5, 6, 0], [6, 2, 0, 9, 5, 2]
[0, 4], [9, 1, 0, 2, 8, 0, 5, 5, 4, 9]
Falsy:
[1], [2]
[2, 4], [5]
[1, 5], [2, 3, 4, 5]
[2, 1, 2, 3, 1, 3], [5, 1, 6]
[4, 4, 5, 2, 4, 0], [9, 2, 10, 1, 9, 0]
Leaderboards
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
# Language Name, N bytes
where N
is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
# Ruby, <s>104</s> <s>101</s> 96 bytes
<script>site = 'meta.codegolf'; postID = 5314; isAnswer = true; QUESTION_ID = 53913</script><script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)</code></pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>
As a mathematician and not a coder, I can't really address the challenge, but I am interested by the following question: If both averages can be raised by shifting some finite collection of integers (say five) from the one set to the other, does it always follow that both averages may be raised by shifting just one integer? Thus showing that the challenge really covers all the cases. – Trevor J Richards – 2015-07-28T12:48:10.893
3@TrevorRichards I think the last falsy test case covers this. You could move a
1
and9
over, which would raise both averages, but you can't do so by moving a single one. – Martin Ender – 2015-07-28T12:52:08.687@TrevorRichards In general, if the sets A & B have averages a & b with a < b then both averages can be raised if there is a subset C of B which has average c such that a < c < b. On the other hand, if you require all elements moved from B to A to have values < b then your hypothesis would be true. – Alchymist – 2015-08-03T12:35:32.370