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

    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"].