Ad
  • Default User Avatar

    For some people it's considered to be the best practice to put break in each case block, even when it's unnecessary like in this example. Reason is that someone can change the code but forget to add break statement which might lead to bugs that are hard to trace.

  • Default User Avatar

    I know it's 11 months old but thanks for explaining this (as if it's a Stack Overflow answer!), it really helped me understand.

  • Custom User Avatar

    This theorem doesn't work for this kata. Think about how to reduce number of cycles of the loop - that's helped me a lot. Before that I got interrupt (more than 6 seconds). After improvement - all tests have been completed in ~ 0.3s (<300ms)

  • Custom User Avatar

    It seems like you are now checking for this but don't mention it in your spec?

  • Custom User Avatar

    I started writing an explanation - but this is better: http://floating-point-gui.de/

  • Custom User Avatar

    Floating point math is notoriously dodgy in most programming environments, and JavaScript is no different. For example, 0.1 + 0.2 == 0.30000000000000004. You'll have to work around it to solve this kata.

  • Custom User Avatar

    Thanks for this comment! I was able to troubleshoot the issues, and I think it should be working now!

  • Default User Avatar

    I can't submit right now, but it seems like now you check that the state falls back to regular in test 15, then you suppose in test 16 that eating a ghost increases points by 10, but the state is now regular, so it occurs to me that this test is wrong since the value should be 0 when you ask for 10, then in test 17 you eat an other ghost, suppose that a life is lost, but a life is already lost in the previous test, therefore you suppose 2 when its 1. I also mention that since I can't submit working code, I can neither see spoiler content nor actual test cases.

  • Custom User Avatar

    edit: This should now be resolved. Thanks for the feedback!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    My mistake. I corrected it.

  • Custom User Avatar

    AFAIK the docs should refer to the current stable implementation while the codewars-runner config is for the beta Docker system, which has an opt-in button in your account settings.

  • Custom User Avatar

    Anyway, if you need to speed this up, try to think of a good maximum value for one of the loop variables.

    For large values, there's a little theorem from number theory that could help:

    X = A^2 + B^2 if and only if for every prime p of the form 4n + 3, p divides X an even number of times

  • Custom User Avatar
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution