In the New Modern Times, when Charlie Chaplin encounters a computer, he is employed in the sorting Yard, as a validator to determine if the workers are correctly sorting the items. The Items in question are packets of marbles. Packets with Odd number of Marbles are stacked in the Red Basket and Packets with Even Number of Marbles are stacked in the Blue Basket.
Charlie Chaplin is supposed to punch the program that would validate if there is any anomaly in the sorting procedure. Mack Swain his immediate Boss, shares an algorithm which he needs to code.
Algorithm
L = List of Marble packets that's already sorted
L_ODD = List of packets with Odd Number of Marbles
L_EVEN = List of packets with Even Number of Marbles
Check_Digit = √(ΣL_ODD² + ΣL_EVEN²)
His Job is to determine the Check_Digit and match it with what ever value his Boss calculates.
Charlie Chaplin during his lunch hours, were able to sneak to Mack Swain's drawer and determine, that his drawer has a single card with punches on the first 46 32 columns (which means Mack was able to write a program with only 46 32 characters).
Charlie Chaplin would now need the help of all the code ninja's to write a program with as few lines as possible. He also announces a bonus of 50 points, if someone can come up with a program which is shorter than his Boss.
Summary
Given a list/array/vector of positive numbers (odd and even), you need to write a function, which would accept the array(int [])/vector<int>/list
and calculate the root of the sum of the squares of the sums of odd and even numbers in the list.
The Size of the program is the size of the body of the function, i.e. excluding the size of the function signature.
Example
List = [20, 9, 4, 5, 5, 5, 15, 17, 20, 9]
Odd = [9, 5, 5, 5, 15, 17, 9]
Even = [20, 4, 20]
Check_Digit = √(ΣOdd² + ΣEven²) = 78.49203781276162
Note, the actual output might vary based on the implementation's floating point precision.
Score
Score is calculated as Score is calculated as Σ(Characters in your Program) - 46
.Σ(Characters in your Program) - 32
.
Apart from the regular upvoting from the community, the lowest negative score would receive an additional bonus of 50 points.
Edit
- The offset that was used to calculate the Score has been changed from 46 to 32. Note, this would not affect the leader-board/ bounty eligibility or invalidate any solution.
Verdict
After a gruesome duel between the Ninjas, Mr. Chaplin received some wonderful answers. Unfortunately few of the answers tried to take undue advantage of the rule and was not very useful. He actually wanted a fair duel and answers where the logic was coded within the function signatures would eventually mean the function signature is an integral part of the solution. Finally, Ninja FireFly was the clear winner and awarded him the bonus he well deserves. Leaderboard (updated every day)
╒══════╤═════════════════╤══════════════╤═════════╤════════╤═══════╕
├ Rank │ Ninja │ Dialect │ Punches │ Scores │ Votes ┤
╞══════╪═════════════════╪══════════════╪═════════╪════════╪═══════╡
│ 0 │ FireFly │ J │ 17 │ -15 │ 6 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 1 │ tmartin │ Kona │ 22 │ -10 │ 2 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 2 │ Sven Hohenstein │ R │ 24 │ -8 │ 7 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 3 │ Ben Reich │ GolfScript │ 30 │ -2 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 4 │ mollmerx │ k │ 31 │ -1 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 5 │ David Carraher │ Mathematica │ 31 │ -1 │ 3 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 6 │ tmartin │ Q │ 34 │ 2 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 7 │ daniero │ dc │ 35 │ 3 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 8 │ psion5mx │ Python │ 38 │ 6 │ 2 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 9 │ O-I │ Ruby │ 39 │ 7 │ 5 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 10 │ gggg │ Julia │ 40 │ 8 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 11 │ FakeRainBrigand │ LiveScript │ 50 │ 18 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 12 │ Sylwester │ Perl5 │ 50 │ 18 │ 2 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 13 │ daniero │ Ruby │ 55 │ 23 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 14 │ vasuakeel │ Coffeescript │ 57 │ 25 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 15 │ dirkk │ XQuery │ 63 │ 31 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 16 │ crazedgremlin │ Haskell │ 64 │ 32 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 17 │ Uri Agassi │ Ruby │ 66 │ 34 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 18 │ Sumedh │ JAVA │ 67 │ 35 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 19 │ Danny │ Javascript │ 67 │ 35 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 20 │ deroby │ c# │ 69 │ 37 │ 1 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 21 │ Adam Speight │ VB │ 70 │ 38 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 22 │ Andrakis │ Erlang │ 82 │ 50 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 23 │ Sp0T │ PHP │ 85 │ 53 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 24 │ brendanb │ Clojure │ 87 │ 55 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 25 │ Merin Nakarmi │ C# │ 174 │ 142 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 26 │ Boopathi │ JAVA │ 517 │ 485 │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 27 │ Noyo │ ES6 │ ? │ ? │ 2 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 28 │ shiona │ Haskell │ ? │ ? │ 0 │
├──────┼─────────────────┼──────────────┼─────────┼────────┼───────┤
│ 29 │ Vivek │ int │ ? │ ? │ 0 │
└──────┴─────────────────┴──────────────┴─────────┴────────┴───────┘