28
2
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
6I came across
æ%
while reading through the built-ins the other day, and it was pretty much made for this (type of) problem:OIæ%13AS
– Martin Ender – 2016-09-17T15:44:53.013I think this is 9 bytes (
æ
is two). – Aleksei Zabrodskii – 2016-09-18T09:48:22.3871
@elmigranto Jelly has a codepage that encodes each of its characters in one byte: https://github.com/DennisMitchell/jelly/wiki/Code-page
– ruds – 2016-09-18T15:54:37.923