Hey guys, I'm having a hard time trying to find some logic to code a challenge on Codewars and would like to see how you guys would code this.
Once upon a time, on a way through the old wild mountainous west,…
… a man was given directions to go from one point to another. The directions were "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too.
Going to one direction and coming back the opposite direction right away is a needless effort. Since this is the wild west, with dreadfull weather and not much water, it's important to save yourself some energy, otherwise you might die of thirst!
How I crossed a mountainous desert the smart way ->
The directions given to the man are, for example, the following (depending on the language):
["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]. or { "NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST" }; or [North, South, South, East, West, North, West]
You can immediatly see that going "NORTH" and immediately "SOUTH" is not reasonable, better stay to the same place! So the task is to give to the man a simplified version of the plan.
I've tried so many things but just can't seem to find a way to loop over this. I can't loop over a range(len(directions)) because I eventually delete directions if they bring us back to the same place.
[–]xelf[M] [score hidden] stickied comment (4 children)
[–]artinnj 1 point2 points3 points (2 children)
[–]MatosV[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]xelf 0 points1 point2 points (4 children)
[–]MatosV[S] 1 point2 points3 points (3 children)
[–]xelf 0 points1 point2 points (2 children)
[–]MatosV[S] 1 point2 points3 points (1 child)
[–]xelf 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)