7 kyu

Distance from the average

2,673 of 4,303GiacomoSorbi
Description
Loading description...
Arrays
Lists
Statistics
Fundamentals
Data Science
  • Please sign in or sign up to leave a comment.
  • EMGROENE Avatar

    JS here. Why would the only test that's failing be the one with a super long array as param?

  • Lukas Pottmann Avatar

    I didn't understand why I should calculate the mean - the value. For me it would make more sense to calculate the value - mean, because if the value is 12 and the mean is 10 I would get 2 more. The way it's asked for here gives -2, when in fact, I collected 2 contacts more. What didn't I understand correctly? There is no way everyone did this wrong, without questioning.

  • anthobio23 Avatar

    push in attempt with cpp. the test doesn't work.

  • Jamba890 Avatar

    Not sure why, but attempt keeps timing out. Using Python. Not calling any special libraries. Help?

  • Daniil2612prac Avatar

    why in nparray I have a right answer, but when I want to use data.tolist() i get it: 4.200000000000003, -35.8, -2.799999999999997, 23.200000000000003, 11.200000000000003 i tried to round by np.round and round every nunmber in list, but it,s unsuccessfull It's awful kata, if you worry about your nervs

  • AlexBaykov Avatar

    I need help with roundind. [4.2, -35.8, -2.8, 23.2, 11.2] All tests are passed but "Execution Timed Out (12000 ms)".

    How can i use """With Clojure to round use: (defn roundTo2 [n] (/ (Math/round (* n 100.0)) 100.0))""" in python???

  • Filin_137 Avatar

    This comment has been hidden.

  • YeshuaNun Avatar

    I didnt like this Kata. Bascially my code is sound and works. PAssed most of the test, but then throws errors with the long array. I think the test is broken. Because all I did was keep hitting 'attempt', without actually checning my code and it worked. I like the Kata from a stats point of view, but think the tests need looking at.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • leehunt Avatar

    C++ tests are broken. For example, the sample tests will fail when running just the initial tests, but the same sample tests will pass when running all the tests.

  • goldenratio161 Avatar

    This comment has been hidden.

  • Barinvic Avatar

    This comment has been hidden.

  • ArthurHakobyan Avatar

    in JS my code perfectly work on jsFiddle but here throing errors.

  • tomasz_nehring Avatar

    I've finally read that I had to round results, but test cases for C++ showing me:

    ExampleTests
    Expected: [ 4.2, -35.8, -2.8, 23.2, 11.2 ]
    Actual: [ 4.2, -35.8, -2.8, 23.2, 11.2 ]
    were really misleading. They were literaly telling me that x is not the answer because the answer is x.

  • arthur2001 Avatar

    Hi GiacomoSorbi and anyone else,

    Would it help to specify that the average ie mean of the values should to 2 decimal places and that differences from average should be to 2 decimal places in return array?

    AND / OR

    Does Blind4Basics have a point where he says => JS: there are rounding troubles in the tests => the assertions should be done with a margin, not with assertSimilar

    I think samtsan is also hinting at the same thing in comments below...

    I noticed even 'top' solution had same problems my solution had in JS in that it worked most times but glitched here and there...

    Just a thought.

    Otherwise excellent kata:)

  • samtsan Avatar

    A tolerance is needed on the comparison. The out can depend on things like if you sum in an int or double, if you round the mean, and probably many other subtle things.

  • besterboris Avatar

    Hi,

    i'm trying to solve your kata in Haskell and I'm interested in your Codewars.Kata.Test.DSL module. Could you show it to me? I need it to run your test in my local environment.

    Thank you :)

  • ejini战神 Avatar

    Missing within_delta() with precision in sample tests of C++

  • Amel  Haracic Avatar

    ExampleTests Expected: [ 4.2, -35.8, -2.8, 23.2, 11.2 ] Actual: [ 4.2, -35.8, -2.8, 23.2, 11.2 ]

    and its not working? can anyone help me? thanks

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • Blind4Basics Avatar

    JS: there are rounding troubles in the tests => the assertions should be done with a margin, not with assertSimilar

  • FArekkusu Avatar

    Python 3.6 is not available. Select it as the default version and VERIFY that it's working.

  • FArekkusu Avatar

    Python 3 should be enabled.

  • michael_gibbons Avatar

    C++ tests are just flat out broken, I copy and pasted the "working" code from the solutions and they all failed.

  • GDoggie Avatar

    This comment has been hidden.

  • StokesM Avatar

    This comment has been hidden.

  • wisyr Avatar

    Any hint how to round it properly in JS, mr Giacomo?

  • danieljoos Avatar

    Seems like this kata does not properly compare double values... rounding issues here.

  • gettinToasty Avatar

    Despite setting up my rounding parts properly I'm getting some weird outputs on the first test: Expecting [4.2, -35.8, -2.8, 23.2, 11.2], instead got: [4.200000000000003, -35.8, -2.799999999999997, 23.200000000000003, 11.200000000000003]

    Anyone know what's up with that? Every other test passes fine.

  • JWNg Avatar

    random tests appear to ask for 2 decimal places.

    here is the output:

    Testing for 67,41,22,-29,-27,-41,49,-32,-65,42,59,89,-99,-61,-56,65,-46,10,2,-15,6,64,-77,-22,88,-7,0,-87,-27,-64,4,-18,7,-5,76,-49,-88,-61,6,64,32,55,-29,78,-24,-78,-26,27,-34,-88,12,9,-39,-80,-87,-36,-2,-81,47,56,0,-85,37,-88,-31,-79,-32,-80,-48,44,45,11,60,-39,2,76,-62,10,57,18,100,-78,9,-65,-45,68,6,70,56,78,-45,-72,4,13,-12,-16,-43,28,72,35
    ✘ It should work for random inputs too - Expected: [-72.24,-46.24,-27.24,23.76,21.76,35.76,-54.24,26.76,59.76,-47.24,-64.24,-94.24,93.76,55.76,50.76,-70.24,40.76,-15.24,-7.24,9.76,-11.24,-69.24,71.76,16.76,-93.24,1.76,-5.24,81.76,21.76,58.76,-9.24,12.76,-12.24,-0.24,-81.24,43.76,82.76,55.76,-11.24,-69.24,-37.24,-60.24,23.76,-83.24,18.76,72.76,20.76,-32.24,28.76,82.76,-17.24,-14.24,33.76,74.76,81.76,30.76,-3.24,75.76,-52.24,-61.24,-5.24,79.76,-42.24,82.76,25.76,73.76,26.76,74.76,42.76,-49.24,-50.24,-16.24,-65.24,33.76,-7.24,-81.24,56.76,-15.24,-62.24,-23.24,-105.24,72.76,-14.24,59.76,39.76,-73.24,-11.24,-75.24,-61.24,-83.24,39.76,66.76,-9.24,-18.24,6.76,10.76,37.76,-33.24,-77.24,-40.24], instead got: [-72.2,-46.2,-27.2,23.8,21.8,35.8,-54.2,26.8,59.8,-47.2,-64.2,-94.2,93.8,55.8,50.8,-70.2,40.8,-15.2,-7.2,9.8,-11.2,-69.2,71.8,16.8,-93.2,1.8,-5.2,81.8,21.8,58.8,-9.2,12.8,-12.2,-0.2,-81.2,43.8,82.8,55.8,-11.2,-69.2,-37.2,-60.2,23.8,-83.2,18.8,72.8,20.8,-32.2,28.8,82.8,-17.2,-14.2,33.8,74.8,81.8,30.8,-3.2,75.8,-52.2,-61.2,-5.2,79.8,-42.2,82.8,25.8,73.8,26.8,74.8,42.8,-49.2,-50.2,-16.2,-65.2,33.8,-7.2,-81.2,56.8,-15.2,-62.2,-23.2,-105.2,72.8,-14.2,59.8,39.8,-73.2,-11.2,-75.2,-61.2,-83.2,39.8,66.8,-9.2,-18.2,6.8,10.8,37.8,-33.2,-77.2,-40.2]

  • sharifahmad Avatar

    My code gives exactly the same output as expected but still it fails. ✘ Expected: [ 4.2, -35.8, -2.8, 23.2, 11.2 ] Actual: [ 4.2, -35.8, -2.8, 23.2, 11.2 ]

  • ssfcultra Avatar

    This comment has been hidden.

  • Dentzil Avatar

    C#-Translation kumited.
    C++-Translation kumited.

  • yurket Avatar

    I can't get something. On haskell I got a test break like this:

    random tests
    works for random non-empty lists
    Falsifiable (after 3 tests): 
    expected: [-15.163720058267302,15.163720058267305]
     but got: [-15.2,15.2]
    [39.247510632792384,8.920070516257777]
    

    Why expected numbers are not rounded up?

  • DerevenetsArtyom Avatar

    my code works right at my comp. but when it goes throught random tests,they fail, BUT the right solution is the same as the solution of this test at my comp. What's wrong???

  • NaMe613 Avatar

    CoffeeScript translation kumited.

  • magthe Avatar

    This comment has been hidden.

  • g964 Avatar

    Clojure translation kumited. If you prefer I can suppress the printing of the given arrays and of the results in the random tests. I gave the rounding method to avoid discussions... I can suppress it too... all as you want:-)

  • g964 Avatar

    @bkaes : It seems that you are not rounding to 2 decimal places or am I wrong somewhere? When I round to 2 decimals I can't pass the random tests but if I don't round at all I can pass.

  • bkaes Avatar

    Haskell translation with a completely arbitrary hspec eDSL kumited :D.

  • bkaes Avatar

    rounding each difference to the second decimal digit

    :(. But I guess you've expected this comment.

  • iamprakashom Avatar

    This comment has been hidden.

  • simplydallas Avatar

    This comment has been hidden.

  • NateBrady23 Avatar

    Good one Giacomo :) Upvoted!

  • g964 Avatar

    In the description you write:

    rounding down each difference to the second decimal digit

    I don't exactly agree: your solution doesn't round ** down ** to 2 decimal places, it simply round to 2 decimal places; sometimes the rounding is up, sometimes down.

  • jmossel Avatar

    difference is defined in unintuitive way. it should be i-average instead of average-i

  • raulbc777 Avatar

    Good one! For me It's ready to go!