QWERTY keyboard string length

1

QWERTY keyboard distance (QKD) is, in short, the distance between two letters/numbers/punctuation keys on a standard QWERTY keyboard (if you don't have one around, you can check this Wikipedia picture). Note that only characters without modifiers be considered for this challenge (so ; is valid, but ) is not).

Some examples:

>> QKD("a","s")
 1
>> QKD("e","f")
 2
>> QKD("g",".")
 5

In this code-golf challenge you will have to compute the QWERTY string length (QSL), which is the sum of the QWERTY keyboard distances between every two consecutive characters of a given string. E.g. QSL("abcd") = QKD("a", "b") + QKD("b", "c") + QKD("c", "d")

Examples:

>> QSL("code-golf")
 37 // QKD(c,o) + QKD(o,d) + QKD(d,e) + .. = 6  +  6 + 1 + 8 + 6 + 4 + 1 + 5 = 37
>> QSL("puzzles")
 25 // 3 + 6 + 0 + 8 + 7 + 1
>> QSL("stackexchange")
 43 // 3 + 4 + 3 + 5 + 6 + 2 + 1 + 3 + 5 + 6 + 2 + 3

Some notes:

  • You have to support at least a-z, 0-9, =[];'\,./ ` and Space.
  • When you aren't sure about the distance between two characters, refer to the Wikipedia picture.
  • Standard loopholes are disallowed, as usual (you knew that, didn't you?).
  • This is , thus shortest code wins.

Bojidar Marinov

Posted 2015-10-08T19:40:42.360

Reputation: 209

Question was closed 2015-10-08T19:52:19.087

@TimmyD Hm... looks similar, but the distance metric is different :) – Bojidar Marinov – 2015-10-08T19:44:22.813

This may not be exactly the same, but it is very similar to the duplicate. This question doesn't really add much that the other one doesn't have. – El'endia Starman – 2015-10-08T19:53:26.967

Ok, no problem... – Bojidar Marinov – 2015-10-08T19:54:26.163

You may not have been aware of this, but on Meta there is a Sandbox where you can post challenges that you'd like to post on the main site and get feedback, including any [almost]-duplicates or requests for clarification, perceived problems pointed out, that sort of thing. It really helps to sandbox your challenges first.

– El'endia Starman – 2015-10-08T20:07:06.250

@El'endiaStarman I'm aware of it.... Just didn't think about it before posting :D – Bojidar Marinov – 2015-10-09T08:38:58.147

No answers