Ad
  • Custom User Avatar

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

  • Custom User Avatar

    You will find that many shell kata's can be solved easier with everything wrapped in a single 'bc' or 'awk' call.

  • Custom User Avatar

    After going back to test the solutions to this kata. Of the 4 variations, 2 no longer run (the method of writing the solution in python and using bash to run python seems to be patched) and the bash method using convolution is also too slow to pass.

    The one solution that works uses bc (a builtin bash library to handle arithmetic operations) runs about 400-800% faster than what I came up with but uses essentially the same logic.

    From what I can see the logic is exactly the same, however in my solution i would pipe statements one at a time to bc instead of writing the entire function in bc. I guess this is just a quirk of bash that you need to find out and remember.

  • Custom User Avatar

    I think this is harder than 5 kyu for bash. The solutions show either literally writing the solution in python as a string and then running that in bash, or leveraging the convolution method.
    If you're working through this in bash and getting timeout errors you need to implement both the algorithms on the wikipedia page or else the program will be too slow

  • Custom User Avatar

    Pro dev here, avoid doing this in production/interviews would be my suggestion. It just makes things more confusing for any other devs your working with, and even your reviewers looking over your PR. Generally the shortest solution for every python problem here is an example of what not to do in production or for interviews.
    That being said, I like doing things like this in my personal code.

  • Custom User Avatar

    If your expecting your arrays to be smaller than it would be much more practical to just use the Sort method from Array. However if you're dealing with an array containing 10^6 elements this method is 25x faster than using sort!