Ad
  • Default User Avatar

    I get that the description says 'right away', so you're only supposed to cancel out immediately adjecent opposites. However that makes no sense as the description also says

    it's important to save yourself some energy, otherwise you might die of thirst

    which clearly sounds like an optimization. Especially the last example in the description ["NORTH", "WEST", "SOUTH", "EAST"] makes no sense why it shouldn't be reduced to []. If you simply follow these instructions as the early settler you would literally end where you started and I'd be pretty upset about the worthless effort 😂

  • Custom User Avatar
  • Custom User Avatar

    To be fair, almost no tutorials teach you Big-O properly. I consistently hear of people that first learned about time and space complexity like 2-5 years after they already begun working as a developer.
    For some reason this isn't taught and unless you prepare for interviews at companies like google, you likely won't hear of this early on.
    I think it should be taught though, it really helps writing better code.

  • Custom User Avatar

    This is O(n^2), not great.

  • Default User Avatar

    "Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible. "NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not directly opposite of each other and can't become such. Hence the result path is itself : ["NORTH", "WEST", "SOUTH", "EAST"]."

    This is false because you'd end up back where you started.

  • Custom User Avatar

    The kata doesn't say that the requirement is to create the most optimal route. It asks you to create the simplified version of the route:

    Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side).

    Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible. "NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not directly opposite of each other and can't become such. Hence the result path is itself : ["NORTH", "WEST", "SOUTH", "EAST"].

  • Custom User Avatar

    This kata is weird.

    I used x and y coordinates to determine the destination and then used those to simply return the most optimal route.

    Example: x: -1 y: 1 would be once WEST and once NORTH.

    The input array was:

    ['EAST', 'NORTH', 'SOUTH', 'NORTH', 'WEST', 'NORTH', 'SOUTH', 'NORTH', 'SOUTH', 'WEST']

    The expected answer is:
    ['EAST', 'NORTH', 'WEST', 'WEST']

    when in reality ['NORTH', 'WEST']
    would be the most optimal and time saving route.

    So now I have to wonder how to get a less optimal solution to fit the weird dependencies of this kata...

  • Custom User Avatar
  • Custom User Avatar

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