Problem 115. Distance walked 1D
Suppose you go from position 7 to 10 to 6 to 4. Then you have walked 9 units of distance, since 7 to 10 is 3 units, 10 to 6 is 4, and 6 to 4 is 2. Total distance traveled = 3 + 4 + 2 = 9.
Example:
Input x = [1 2 3 2] Output y is 3
Solution Stats
Problem Comments
-
11 Comments
Amitava, can you give a clearer idea of what your function inputs and outputs should look like?
If you leave one test the solution is simply 9. As is this submission is very poor.
Needs generalization and a larger test suite.
This is a pretty good idea for a problem but it's *very* poorly stated.
I cleaned up the problem statement and added a few more tests.
good idea...
Very good problem. I had to solve the same one to determine whether a signal was oscillating or stable.
Interesting problem
nice problem
nice...
Great problem!
Solution Comments
Show commentsProblem Recent Solvers2445
Suggested Problems
-
Which values occur exactly three times?
4938 Solvers
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1645 Solvers
-
Number of 1s in a binary string
8069 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
595 Solvers
-
1339 Solvers
More from this Author100
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!