Hey there, it's time to get moving.
Today’s challenge is modified from user @JKphobic on CodeWars:
You live in a city where all roads are laid out in a perfect grid. You have the unfortunate habit of arriving too early or too late to your appointments, so you decide to create a Walk Generating App.
Any time you press the button, it will send you an array of one-letter strings representing directions to walk (eg. [‘n’,’s’,’w’,’e’]). You always walk only a single block in a direction. It takes one minute to traverse one city block.
Create a program that will return an array of one-letter strings representing the walk. The program should accept input for the amount of time the user decides to walk and should bring the user back to their starting location.
I wish the streets in my town were structured like this, it would make driving so much easier.
Good luck, happy coding!
Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (21)
During my reflexion about this challenge, I figured out that if input is an odd number, you will never be able to go back at your start position.
Here my JS implementation:
Powershell
I went the voluntary choice route with a voluntary initial route, and reversing it to get back.
My solution in Swift language :
PHP
BASH
PHP
Some comments may only be visible to logged-in visitors. Sign in to view all comments.