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
Show
8 older comments
Venkatapathi
on 31 Dec 2013
nice problem
vahid simintan
on 8 Apr 2016
nice...
Shane Murphy
on 26 Apr 2017
Great problem!
Solution Comments
Show commentsProblem Recent Solvers2495
Suggested Problems
-
Sum all integers from 1 to 2^n
15907 Solvers
-
Project Euler: Problem 5, Smallest multiple
1505 Solvers
-
"Low : High - Low : High - Turn around " -- Create a subindices vector
548 Solvers
-
Who is the smartest MATLAB programmer?
763 Solvers
-
473 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!