7 kyu

Same Birthday Probability

406 of 831user5467385
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • XoRMiAS Avatar

    JavaScript fork (author gone)

    • Updated to Node 18 and chai
    • Tests are now in line with the description (resolves this issue)
      • Backwards compatible, so old solutions will not be invalidated
    • Does not address this issue, as per my comment.
  • XoRMiAS Avatar

    Description is incorrect for JavaScript. The tests always require two decimals, even for 0 and 1, which directly contradicts the description. In addition, the tests expect strings instead of numbers.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • jebreen Avatar

    What rounding are you using? I got an error for 18 people where the reference solution expect 0.35 but I return 0.34

    The calculation comes out at 0.34279 when rounded to 5 places, which is 0.34 rounded to 2 places.

    You need to allow for differences in round and an error of +/- 0.01 or specify round UP or DOWN to 2 places...

  • FArekkusu Avatar

    The values have to be compared for approximate equality, especially when the difference between the result of an O(1) formula and the value returned by the reference solution (without rounding) can be as high as 0.01 - have fun dealing with numerous off by one errors.

  • macnick Avatar

    When the kata is not about programming but a mere math formula coding it is better to give the formula. It took me 25 minutes to find the formula and 1 to code it.

  • tmfield Avatar

    This comment has been hidden.

  • glynester Avatar

    Can someone please tell me how to round this because I am only out about by 0.01 on an average of 4 out of 23 test cases:

    ✔ Test Passed: Value == 1 ✔ Test Passed: Value == 0.97 ✔ Test Passed: Value == 1 ✘ calculateProbability(15) - Expected: 0.25, instead got: 0.26 ✔ Test Passed: Value == 1 ✔ Test Passed: Value == 1 ✔ Test Passed: Value == 0.92 ✘ calculateProbability(15) - Expected: 0.25, instead got: 0.26 ✔ Test Passed: Value == 0.81 ✔ Test Passed: Value == 0.75 ✔ Test Passed: Value == 0.73

    etc.

  • marisid Avatar

    Thanks for this kata @Et2rn1ty! I would suggest to rephrase your description to clarify that you are asking for the probability of at least (and not any) two people having their birthday on the same day. This is actually the probability we are calculating in this kata. Other than that, very good idea.

  • grone Avatar

    I am getting the right answers but still the test is being failed, any idea what could be wrong? Thanks in advance! calculateProbability(81) - Expected: 1, instead got: 1.00 calculateProbability(78) - Expected: 1, instead got: 1.00 calculateProbability(40) - Expected: 0.89, instead got: 0.89 calculateProbability(42) - Expected: 0.91, instead got: 0.91 calculateProbability(12) - Expected: 0.17, instead got: 0.17 calculateProbability(100) - Expected: 1, instead got: 1.00

  • GiacomoSorbi Avatar

    Nice kata: Python and Ruby translations submitted, if you want to approve them :)

  • kyle.johnson Avatar

    I like this kata, but have a few suggestions. It might be better to frame the problem better and to specify that we should expect the birthdays to be distributed uniformly. It might also be better to specify that we are looking for a number between 0 and 1 and not something like 0-100.

  • jgdodson Avatar

    The description is silghtly terse. I might recommend framing the problem a bit, mentioning that it is a very famous problem from probability, and giving the coder a little motivation. Also, I will say that kata live and die by the number of default tests provided. Good problem!!

  • TheDoctor Avatar

    There needs to be more than one test case. The test you have is fine, it just needs to run a few more times.

  • Azuaron Avatar

    You need some example test cases and much better failure messages in your test cases. "Value was not as expected" is completely useless for debugging.

  • laoris Avatar

    I've tried computing this a few different ways and haven't been able to succeed yet. It's going to be difficult to match the expected answers exactly due to accumulated errors from floating-point rounding. Perhaps the tests could just check the first few digits of the answer?