def get_walk(minutes):
if minutes % 2 != 0:
# Only even minute times are possible, as you always need to walk the same distance east as west,
# andnortha s sound.
raise ValueError("Only walks with an even number of minutes are possible")
half = minutes / 2
return half * ['n'] + half * ['s']
If you add the requirement that you can't walk the same street twice...
def get_walk(minutes):
if minutes % 2 != 0:
# Only even minute times are possible, as you always need to walk the same distance east as west,
# andnortha s sound.
raise ValueError("Only walks with an even number of minutes are possible")
# We'll return a rectangle with width 1, so the two short sides combined take 2 minutes
# We'll divide the remaining minutes by 2 to know how long the other sides should be.
length = (minutes - 2) / 2
return ['n'] + length * ['e'] + ['s'] + length * ['w']
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's a trivial solution in Python
If you add the requirement that you can't walk the same street twice...