10
1
In this challenge you will be determining how controversial a vote is, given an array of other votes, by figuring out a number called the C-factor. What is the C-factor, you ask?
Well, imagine you've got multiple votes on an election. We'll use 1
and 0
for the sake of the challenge to represent two different candidates in an election. Here's the ten votes in our sample election:
0110111011
Now, say we want to find the C-factor of any vote for candidate 0
. We can do that with the following function:
$$ f(o,v) = abs(o-mean(v)) $$
In \$f\$, o
is the vote we want to determine the C-factor for, and v
is an array of votes. So, using our function, to get the C-factor of any vote for candidate 0
:
$$ f(0, [0,1,1,0,1,1,1,0,1,1]) = 0.7 $$
A lower C-factor shows that the vote was less controversial in comparison to the other votes. So, a vote for candidate 0
is more different from the other votes than a vote for candidate 1
. In comparison, the C-factor for a candidate 1
vote is \$0.3\$, so it is less controversial because it is more like the other votes.
The Challenge
Write a function \$f(o,v)\$ to determine the C-factor of a vote o
given results of a vote v
.
o
must be an integer, either0
or1
.v
must be an array (or similar container type depending on language specifications) of arbitrary length containing zeroes and ones.The function should return or print to the console the resulting C-factor given the function parameters, using the formula above or a modified method.
Good luck! The least bytes wins (winner chosen in five days).
Isn't
mean(v)
equal to 0.7 in your example? – HyperNeutrino – 2019-06-19T13:22:31.817@HyperNeutrino Yes. What's the issue? – connectyourcharger – 2019-06-19T13:23:25.240
How is
abs(0 - 0.7)
equal to0.3
? – HyperNeutrino – 2019-06-19T13:23:40.863Ah. Fixed the example. I reversed the two numbers – connectyourcharger – 2019-06-19T13:24:39.340
Oh okay. Thanks for clarifying! – HyperNeutrino – 2019-06-19T13:24:51.880
Can one's program output a fraction? – LegionMammal978 – 2019-06-24T20:47:31.710