Challenge
Given an input of an all-lowercase string [a-z]
, output the total distance between the letters.
Example
Input: golf
Distance from g to o : 8
Distance from o to l : 3
Distance from l to f : 6
Output: 17
Rules
- Standard loopholes forbidden
- This is code-golf - shortest answer in bytes wins.
- The alphabet can be traversed from either direction. You must always use the shortest path. (i.e the distance between
x
andc
is 5).
Test cases
Input: aa
Output: 0
Input: stack
Output: 18
Input: zaza
Output: 3
Input: valleys
Output: 35