Ad
  • Custom User Avatar

    You should defer calculations of sqrt as late as you can (not do it right away), trying to return as early as you can, and considering various edge cases.

  • Custom User Avatar

    Cool! I haven't seen a ternary used like this.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    What does this kata add that other kata's about primes haven't done before?

  • Custom User Avatar

    I enjoyed everything, it was an awesome challenge.

  • Custom User Avatar

    ready

  • Custom User Avatar

    ready

  • Custom User Avatar

    ready

  • Custom User Avatar

    Very confusing description. (Copy paste the markdown)

    Task :

    Hello, warrior!

    In this kata, you need to complete the function sum_not_prime, which takes two parameters :

    • max_prime.
    • max_num.
      and must return an array of length max_num where for each index 0 <= i <= max_num -1 :
    array[i] = \sum_{p \, \le max-prime, p | i} p
    

    Example :

    • sum_not_prime(10, 15)
      The primes that need to be considered : $2$, $3$, $5$ and $7$.

      1. With $p=2$ : [0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2]
      2. With $p=3$ : [0, 0, 2, 3, 2, 0, 2+3=5, 0, 2, 3, 2, 0, 2+3=5, 0, 2]
      3. With $p=5$ : [0, 0, 2, 3, 2, 5, 5, 0, 2, 3, 2+5=7, 0, 5, 0, 2]
      4. With $p=7$ : [0, 0, 2, 3, 2, 5, 5, 7, 2, 3, 7, 0, 5, 0, 2+7=9]

      Final result : [0, 0, 2, 3, 2, 5, 5, 7, 2, 3, 7, 0, 5, 0, 9]

    Note :

    Although 0 % prime == 0, index 0 is always excluded from being updated.

  • Custom User Avatar

    The description isn't clear. I needed to study the example pretty carefully to figure out what needed to be done. For one thing, it should be clarified that the prime divisor is never added to the element at index 0, despite the fact that 0 % [prime] equals 0.

  • Custom User Avatar
    • Random tests should be put inside the actual tests suite, not Preloaded.
    • There should be some fixed tests in there, too
  • Custom User Avatar

    This code that's "too slow" would pass easily in most other available languages (probably all of them, but I haven't checked some yet).

    Now because you're using such huge numbers that bash can't handle, we have to use tools like bc or awk. But even the few solutions that do this entirely with bc/awk (naive approach) either pass in 11-12s, or time out. That is too strict IMO. You either have to pray that your implementation is good enough, or resort to using some kind of formula to speed it up, which isn't required for other languages.

  • Custom User Avatar

    I'm not sure what makes you ask that, because it shouldn't be. The code you posted is missing a few brackets (check the syntax for do-while loops), otherwise it passes all tests.

  • Custom User Avatar

    Added some now

  • Loading more items...