1
\$\begingroup\$

This question already has an answer here:

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.
\$\endgroup\$

marked as duplicate by AdmBorkBork, Blue, Beta Decay, Geobits, El'endia Starman Oct 8 '15 at 19:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ @TimmyD Hm... looks similar, but the distance metric is different :) \$\endgroup\$ – Bojidar Marinov Oct 8 '15 at 19:44
  • \$\begingroup\$ 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. \$\endgroup\$ – El'endia Starman Oct 8 '15 at 19:53
  • \$\begingroup\$ Ok, no problem... \$\endgroup\$ – Bojidar Marinov Oct 8 '15 at 19:54
  • \$\begingroup\$ 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. \$\endgroup\$ – El'endia Starman Oct 8 '15 at 20:07
  • \$\begingroup\$ @El'endiaStarman I'm aware of it.... Just didn't think about it before posting :D \$\endgroup\$ – Bojidar Marinov Oct 9 '15 at 8:38

Browse other questions tagged or ask your own question.