[Question]
  [
We are all used to the old-school telephone keypad, right? For reference, here is what it looks like:
[![Telephone Keybad](https://i.stack.imgur.com/MPi6I.png)](https://i.stack.imgur.com/MPi6I.png)
---
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 `abc` written down on it. In order to type `a`, you must press this key once, for `b` you must press twice and for `c` you 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 `7` and `9` have 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", " "
```
# Test Cases
```
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)
```
# Specs
* 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](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest answer *in every language* wins.
  
[Answer]
# JavaScript (ES6) ~~77~~ ~~66~~ ~~64~~ 60 bytes
(Saved some bytes thanks to @Johan Karlsson and @Arnauld).
```
s=>[...s].map(l=>s=~~s+2+'behknquxcfilorvysz'.search(l)/8)|s
```
```
f=
s=>[...s].map(l=>s=~~s+2+'behknquxcfilorvysz'.search(l)/8)|s
console.log(f(''));                 //0
console.log(f('water'));            //8
console.log(f('soap'));             //9
console.log(f('candela'));          //13
console.log(f('code golf'));        //20
console.log(f('king of the hill')); //33
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~29~~ ~~26~~ 25 bytes
```
ð¢svA•22ā₂•S£ð«øðδKy.åƶOO
```
[Try it online!](https://tio.run/##MzBNTDJM/f//8IZDi4rLHB81LDIyOtL4qKkJyAo@tBgovPrwjsMbzm3xrtQ7vPTYNn////@zM/PSFfLTFEoyUhUyMnNyAA "05AB1E – Try It Online")
**Explanation**
```
ð¢                         # count spaces in input
  sv                       # for each char y in input
    A                      # push the lowercase alphabet
     •22ā₂•S               # push the base-10 digit list [3,3,3,3,3,4,3,4]
            £              # split the alphabet into pieces of these sizes
             ð«            # append a space to each
               ø           # transpose
                ðδK        # deep remove spaces
                   y.å     # check y for membership of each
                      ƶ    # lift each by their index in the list
                       O   # sum the list
                        O  # sum the stack
```
[Answer]
# [Python 2](https://docs.python.org/2/), 56 bytes
Uses the same algorithm as [@RickHitchcock's Javascript solution](https://codegolf.stackexchange.com/a/128827/64121)
```
lambda x:sum('behknquxcfilorvysz'.find(c)/8+2for c in x)
```
[Try it online!](https://tio.run/##Jc1LDsIgFIXhuau4MyBWTToyTXQj6oDyEFLKRUq1tenaUXR0vjP6w5wM@jrr0zU73reSw9QMY09Jq0znH@MktHUYn/PwJnttvaSCHY7bWmMEAdbDxHJxUkMq90JIBeTFk4oFA/JQVnAvleM/olRwR6fL6ay/A2pIRoGxzpFbswEI0foEZFlhd4Zl/YYx9jzRqEKkpcQq0H@w/AE "Python 2 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~69~~ ~~67~~ ~~65~~ 64 bytes
1 byte thanks to Mr. Xcoder.
1 byte thanks to Felipe Nardi Batista.
```
lambda x:sum((ord(i)+~(i>"s"))%3+3*(i in"sz")+(i>" ")for i in x)
```
[Try it online!](https://tio.run/##VclNCsMgEEDhfU8xDBRm6tJdITlJNpbEOsRoUEt@Fr26rZtCl@9761FcDLrabqjeLI/RwH7Pr4UoppGE1Zukx4zMV630jQQkYD6RVXNAtjFBQ9i5rklCIUvN@fKrzZQp/cks4QnRQnETOPH@O@sH "Python 3 – Try It Online")
[Answer]
# Dyalog APL, 37 bytes
```
+/⌈9÷⍨'adgjmptw behknqux~cfilorvy~'⍳⍞
```
[Try it online!](https://tio.run/##RYs7DsIwEET7nMJdChRRc5yNfzFZvCY2hFCkJQW@AjU9BQfgJr6IEUiYqea90YDDRkyApBuO4L3hOS0XlVfrdF02r2eK9xqE3u5cGFkru97uD6eZK4M0HKe5TvGR4u3zyewbVVW/MkKQQyFP4ApwsEIiFG5BSzz/ZxKSaUJVTG@sZqRY6CTrDOIb)
**How?**
Get the `⍳`ndex of every char of the input in the string `'adgjmptw behknqux~cfilorvy~'` (`s` and `z` will default to 28), divide by 9, round up and sum.
[Answer]
## JavaScript (ES6), 71 bytes
```
f=
s=>[...s].map(c=>t+=((c=parseInt(0+c,36))>23?c+3:c&&~-c%3)%7%4+1,t=0)|t
```
```
<input oninput=o.textContent=f(this.value)><pre id=o>
```
Look no letter tables! I didn't quite understand @LeakyNun's formula so I came up with my own.
[Answer]
# C, ~~211~~ 196 bytes
First submission here...looks quite lengthy and I see that this is not an efficient approach, but at least it works :)
```
f(char*n){char*k=" abcdefghijklmnopqrstuvwxyz";int t[]={0,3,3,3,3,3,4,3,4};int l=0,s,j,i;while(*n){i=0;while(k[i]){if(k[i]==*n){s=0;for(j=0;s<i-t[j];s+=t[j++]);*n++;l+=(!i?1:i-s);}i++;}}return l;}
```
Ungolfed version:
```
int f(char *n){
  char *k=" abcdefghijklmnopqrstuvwxyz";
  int t[]={0,3,3,3,3,3,4,3,4};
  int l=0,s,j,i;
  while(*n){                          // loop through input characters
    i=0;
    while(k[i]){
      if(k[i]==*n){                   // find matching char in k
        s=0;
        for(j=0;s<i-t[j];s+=t[j++]);  // sum up the "key sizes" up to the key found
        *n++;
        l+=(!i?1:i-s);                // key presses are i-s except for space (1)
      }
      i++;
    }
  }
  return l;
}
```
[Answer]
# Haskell - ~~74~~ ~~71~~ 62 bytes
*Edit: removed 3 bytes by using a list comprehension instead of filter*
*Edit: Save 9 bytes thanks to Siracusa, Laikoni and Zgarb!*
```
f=sum.(>>= \x->1:[1|y<-"bcceffhiikllnooqrrsssuvvxyyzzz",y==x])
```
## Usage
```
λ> f "candela"
13
λ>
```
[Try it online!](https://tio.run/##ZckxDsIgFADQ3VP8EAdNbJOuRnoRdcAChfSXX6GtQLw77rK@Z0SYFGIpmodtbk99z@ERm7673rtvujXsNQxKa2PthOiI3t6HELZ9jynlnNklcR6f5zIL64CDpAPA4q1boQUNR2DsHz5iVb7SQGKpcBBOKhS1k1QwEupqJutGIA2rUWAsIis/)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 25 bytes
```
Øaḟ⁾sz©;⁶s3Z®ṭċ@€€⁸×"J$ẎS
```
[Try it online!](https://tio.run/##y0rNyan8///wjMSHO@Y/atxXXHVopfWjxm3FxlGH1j3cufZIt8OjpjUg1Ljj8HQlL5WHu/qC////n5yYl5KakwgA "Jelly – Try It Online")
[Answer]
## Clojure, ~~82~~ 76 bytes
```
#(apply +(for[c %](+(count(filter #{c}"bcceffhiikllnooqrrsssuvvxyyzzz"))1)))
```
Oh it is simpler to just `filter` and `count` than use `frequencies`. Original:
```
#(apply +(count %)(for[c %](get(frequencies"bcceffhiikllnooqrrsssuvvxyyzzz")c 0)))
```
The string encodes how many times more than just once you need to press the key for a given character :)
[Answer]
# [Python 3](https://docs.python.org/3/), 91 bytes
```
lambda x:sum(j.find(i)+1for j in' !abc!def!ghi!jkl!mno!pqrs!tuv!wxyz'.split('!')for i in x)
```
[Try it online!](https://tio.run/##VYtBDsIgEADvvmK3FyAmTYw3E3/ihbZQllJAoLb181gvJh5nJhP3YoK/Vn1/VCfnbpCw3fIyc9tq8gMncb7okMACeQYoux4HpXE0hHZyOPuA8ZkyluWF67a/WZujo8IZMvH96PhgEzUm8oVr3kAjxOlHqywq/ZmJ/AhBQzEKDDl3xPoB "Python 3 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 60 bytes
Probably sub-optimal, as this is my first golf ever in Python.
```
lambda x:sum((ord(i)-8)%3.15//1+3*(i>'y')+(i>' ')for i in x)
```
[Try it online!](https://tio.run/##VclBCsIwEIXhvaeYjSRj0VKCIIKexE00STOYZkIasT191I2Q1eP/XlqL56iqu9xq0NPdaFjO82uSkrORhPsTbtVhOPb90KmdpKtYBXa/BYGOMxBQhAVryhSLdFIIxM0/3rrY3MjMOjXw0NHYoFtjY2Hk4Bp9UhyBHRRvwVMI37N@AA "Python 3 – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~46~~ 36 bytes
*Thanks to CalculatorFeline for saving 6 bytes.*
```
s|z
,c
[cfilorvy]
,b
[behknqux]
,,
.
```
[Try it online!](https://tio.run/##DcdBDoMgEAXQ/T8FGxMXpNfwEMTEEQchTpgWaWsb746@3StcU6bW9cPU9vMP6@F8SKLl8xthZ7iZ45Zf7@OexaM1fKlywa70hKe8sBC8LmxWlYAt5dVoMDWyiUnkAg "Retina – Try It Online")
[Answer]
## Java, ~~95~~ 73 bytes
```
a->a.chars().map(b->1+(b<64?0:b+(Math.abs(b-115)<4?4:5))%(3+b/112)).sum()
```
Thanks to Kevin Cruijssen for making the function a lambda expression (where `a` is of type `String`). 95 bytes became 73 bytes!
A lambda expression sums up the press count of each character using `map()`. `map()` converts each character (ASCII in lower case range is 97-122) in the stream to the appropriate value (looks like simple saw wave, but taking into account both 4 cycles is annoying) using this math: `1+(b<64?0:b+(Math.abs(b-115)<4?4:5))%(3+b/112)`. [Here's](https://www.desmos.com/calculator/86ii5wwvmg) a desmos graph of that model.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~100~~ 90 bytes
```
a:qb:["abc""def""ghi""jkl""mno""pqrs""tuv""wxyz"s]Fc,#a{Fd,#b{e:((bd)@?(ac))e<4?i+:e+1x}}i
```
Check each character of the input for a match in each element of b. The index of that match plus 1 gets added to the total.
[Try it online!](https://tio.run/##BcFLDoIwFAXQrTSXSRuYmDhqTHDEJgyDfh70SYUiqChh7fWcxClno2erbzDWAZ46oA8M3IcIPMYJSPNzAdbXG/hs3x@WtnFVYfbGV4XdSUtpvbrW0jil6HKuudRUnrbj4JwHHnsxdWINJALH@Ac "Pip – Try It Online")
[Answer]
# Mathematica, 83 bytes
```
c=Characters;Tr[Tr@Mod[c@"bc1def1ghi1jkl1mno1pqrstuv1wxyz "~Position~#,4]+1&/@c@#]&
```
[Answer]
# [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 94 bytes
```
[_l;||_SA,a,1|p=p-(instr(@sz`,B)>0)-(instr(@cfilorvy`+C,B)>0)-(instr(@behknqux`+C+D,B)>0)+1}?p
```
## Explanation
```
[    |      FOR a = 1 TO
 _l |         the length of
   ;            the input string (A$)
_SA,a,1|    Take the a'th char of A$ and assign it to B$
p=p         p is our tap-counter, and in each iteration it gets increased by the code below
            which consist of this pattern:
                instr(@xyz`,B)>0    where 
                - instr tests if arg 2 is in arg 1 (it either returns 0 or X where X is the index of a2 in a1)
                - @...` defines the letters we want to test as arg1
                - B is the current letter to count the taps for
            Each of these blocks adds 1 tap to the counter, and each block has the letters of its level
            (4-taps, 3-taps or 2-taps) and the level 'above' it.
    -(instr(@sz`,B)>0)              <-- letters that require 4 taps
    -(instr(@cfilorvy`+C,B)>0)      <-- 3 or 4 taps
    -(instr(@behknqux`+C+D,B)>0)    <-- 2, 3,or 4 taps
    +1                              <-- and always a 1-tap
}           NEXT
?p          PRINT the number of taps
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/), ~~69~~  68 bytes
```
bc<<<`fold -1|tr "\n "adgjmptwbehknquxcfilorvysz +[1*9][2*8][3*8]44`
```
[Try it online!](https://tio.run/##S0oszvj/PynZxsYmIS0/J0VB17CmpEhBKSZPQSkxJT0rt6CkPCk1IzuvsLQiOS0zJ7@orLK4SkE72lDLMjbaSMsiNtoYSJiYJPz/n5yfkqqQnp@T9v8/AA "Bash – Try It Online")
Folds one char per line, transliterates each newline with `+`, each space with `1` and each letter with the corresponding number of pushes. bc does the sum.
[Answer]
## C, 92 88 bytes
```
c,n;f(char*s){n=0;while(c=*s++)n+=(c=='s')+3*(c>'y')+1+(c+1+(c<'s'))%3-(c<33);return n;}
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 36 bytes
```
{+/(3×⍵∊'sz'),1+3|¯1+⍵⍳⍨819⌶⎕A~'SZ'}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhGptfQ3jw9Mf9W591NGlXlylrqljqG1cc2i9oTZIrHfzo94VFoaWj3q2Peqb6linHhylXgvUqaCuzgUkyhNLUovArOL8xAIwIzkxLyU1JxHMTkpMT82pggjnp6QqpOfnpIF52Zl56Qr5aQolGakKGZk5OeoA "APL (Dyalog Classic) – Try It Online")
Finds the mod-3 indices in the alphabet without *S* and *Z*. Since space, *S*, and *Z* are not found, they "have" index 25 (one more than the max index), which is good for space. Then we just need to add 3 for each *S* or *Z*.
`{` anonymous function where the argument is represented by *⍵*:
 `⎕A~'SZ'` the uppercase **A**lphabet, except for *S* and *Z*
 `819⌶` lowercase
 `⍵⍳⍨` the **ɩ**ndices of the argument in that
 `¯1+` add negative one
 `3|` mod-3
 `1+` add one (this converts all 0-mods to 3)
 `(`…`),` prepend:
  `⍵∊'sz'` Boolean where the argument is either *s* or *z*
  `3×` multiply by 3
 `+/` sum
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 75 ~~77~~ bytes
```
n,b;f(char*a){for(n=0;b=*a++;)n+=b<'s'?--b%3+(b>31):""[b-'s'];a=n;}
```
The unprintable string `""` is a table of `04 01 02 03 01 02 03 04`.
[Try it online!](https://tio.run/##fYpBDoIwFESjsuIUTRNCC5Jg2FnRg6iL39ICEX9JwbggnB27ciVOZjGZ91RWK7UsuJfCMNWAS4BPxjqGZS5kmUCaCo5pKU/xEF@yTEZFyuS5OPAjDTbbnW9ArzLz9C6gRDEvLY7kCS0yHk4h8emdvwyjUXVDuveDci5@kzeM2q3jwUK/ThVgpTv4I9hKk9p2Zl15tFgTa8jYaNK0Xfc1nR5fDkkuwjlcPg "C (gcc) – Try It Online")
]