We are all used to the old-school telephone keypad, right? For reference, here is what it looks like:
Given a String consisting only of lowercase ASCII letters and single spaces, your task is to return the number of taps one should make in order to type down the full String with a telephone keypad as the one above.
For those who are unfamiliar with this, here's how it works:
The key with the digit
2, for example, also has the string
abcwritten down on it. In order to type
a, you must press this key once, for
byou must press twice and for
cyou must press thrice.
For consecutive letters that are on the same key, you must wait 1 second before pressing again. So, if you want to type
cb, you must press 3 times for
c, wait a second and then press twice for
b, so still 5 taps.
The same applies for all other keys, except for a single space, which only requires 1 press. Also note that the keys
9have four letters on them. The same algorithm is applied, the only difference being the number of letters. The strings corresponding to each key can be found in the image above (but lowercase), or in the following list, that contains all the characters you might receive:
"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz", " "
Input -> Output (Explanation) "" -> 0 (nothing should be tapped) "water" -> 8 ("w,a,t" each require 1 tap (on keys 9, 2 and 8), "e" requires 2 taps (on key 3), "r" requires 3 taps (on key 7), 1+1+1+2+3 = 8) "soap" -> 9 (4+3+1+1) "candela" -> 13 (3+1+2+1+2+3+1) "code golf" -> 20 (3+3+1+2+1(for the space)+1+3+3+3) "king of the hill" -> 33 (2+3+2+1+1+3+3+1+1+2+2+1+2+3+3+3)
Standard I/O rules and Default Loopholes apply.
You may only take input in your language's native String type. Output can either be an integer or a string representation of that integer.
This is code-golf, the shortest answer in every language wins.