[Question]
  [
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requires navigating a keyboard that looks like this:
```
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 1 2 3 4
5 6 7 8 9 0
```
Your task is to take as input a movie title and calculate how "frustrating" it is to type that movie title. The frustration number of a particular string is the number of letters that require moving right from the letter before them. We don't care how far right they are, since if we start moving right we pretty much instantly go to the end of the line, and we don't care about up, down or leftwards movement because they are easy.
For example if we wanted to type in
```
keyboard
```
* We start at `k` for free.
* `e` is just above `k` so we don't need to move right.
* `y` is all the way left so no need to move right.
* `b` however is on the next column rightwards so we need to move right to get to it.
* `o` is on the next column over so we have to move rightwards to get to it.
* `a` is back in the first column so we move left to get to it.
* `r` is all the way on the right so we move right to it.
* `d` is two columns to the left of `r`'s column.
The characters that need to move to the right are `bor` meaning that this is frustration 3.
## Additional rules
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge so your answers will be scored in bytes with fewer bytes being better. The input will always consist of alphanumeric characters, you can support either capital or lowercase letters and you only need to support one. The input will never be empty.
## Testcases
```
keyboard -> 3
2001aspaceodyssey -> 6
sorrytobotheryou -> 8
thinblueline -> 5
blast2 -> 3
```
  
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~61~~ ~~55~~ 54 bytes
*Saved 1 byte thanks to @nwellnhof*
Takes input as an array of characters.
```
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
```
[Try it online!](https://tio.run/##bc5BCsIwEIXhvacQQUhQY1UUEVLBa4iLNJ3aauyEmVQIiFevRVEQOqtZfA/@i7kbtlT5MKsxh7bQLeuU1c144bXVKU20T7tXTOz@aXeL2aEpCiBh5TE5yfFGTkkn8kGtxZrRgXJ4FoU4KqVGV4gZGspHJymH35vPh6tBD14myYK9sYB5ZIb4HnV404cZiWLADEMJFLH54m0fDmVVZ64BV9XwS@nwug9nznBY/hV/mtsX "JavaScript (Node.js) – Try It Online")
### How?
For all characters but digits greater than \$0\$, the 0-indexed column \$x\$ is given by:
$$x=(c-1)\bmod 6$$
where \$c\$ is the ASCII code of the character.
For positive digits \$n\$, we need to do instead:
$$x=(n+1)\bmod 6$$
*Examples:*
```
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 =  4 mod 6 = 4
```
### Commented
```
s =>                       // s = input string (as array)
  s.map(p =                // initialize p to a non-numeric value
  c =>                     // for each character c in s:
    r +=                   //   update the result r:
      p > (                //   compare p with
        p = (              //   the new value of p defined as:
          +c ?             //     if c is a positive digit:
            ~c             //       -(int(c) + 1)
          :                //     else:
            1-Buffer(c)[0] //       -(ord(c) - 1)
        ) % 6              //     apply modulo 6
      ),                   //   yields 1 if the previous value is greater than the new one
    r = 0                  //   start with r = 0
  ) | r                    // end of map(); return r
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
⁾04yO‘%6<ƝS
```
A monadic Link accepting a list of (uppercase) characters.
**[Try it online!](https://tio.run/##y0rNyan8//9R4z4Dk0r/Rw0zVM1sjs0N/v//v5GBgaFjcICjs6u/S2RwsGskAA "Jelly – Try It Online")**
### How?
First replaces any `'0'`s with `'4'`s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by `6` to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
```
⁾04yO‘%6<ƝS - Link: list of characters         e.g. "BLAST20"
⁾04         - list of characters = ['0', '4']
   y        - translate                             "BLAST24"
    O       - ordinals                              [66,76,65,83,84,50,52]
     ‘      - increment                             [67,77,66,84,85,51,53]
       6    - literal six
      %     - modulo                                [ 1, 5, 0, 0, 1, 3, 5]
         Ɲ  - neighbourly:
        <   -   less than?                          [  1, 0, 0, 1, 1, 1  ]
          S - sum                                   4
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~45~~ 39 bytes
```
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
```
[Try it online!](https://tio.run/##BcFRCoMwDADQq@RjDh2sqAy/dOeQjTFajSirRpL2I4hn797bkX2TVoXrBF06JK5g3pUxt8@rvXxPOvIa@rshHqXos0cDfdacSazClJs4FDARQ/tDdWR5hLosKyu7HZBGFUEFIWYN5CjMyEoRwrxszkf0y4bgvJVQP9Mf "Perl 6 – Try It Online")
Works with uppercase letters. `(2-ord(c))%46%6` computes the reversed x coordinate.
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 85 bytes
```
import StdEnv
(\s=sum[1\\a<-s&b<-tl s|b>a])o map(\e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
```
[Try it online!](https://tio.run/##rZI/b9swEMVn61PcVEmpVFkpGrSAlakdAnQokNHycJTONVH@UcljEwH97FVJOU6QPdu9e@C7H48cFKFZtB2DItAoTdZcQdOA1JN17GFAkzPgNBE6kMbLkQAN0OPkyHtpDfAJGYInHysChVqMCMdgBo5ulQGkOG9Xd7DxuLCPIGOy1ZoM0wg2MIiwhoxwtA7YMioQM6cTwfCH5YwD9zx@M3@yovedD3rf9j3uav9O7GpW4P@KWzyUNl5jKnrqCrZ3hoHey2NBdd7mt3mTly3UbelIw025XDWJLYEJUvbhmTrhxYsalgOqamUzqCNcYSyDo99BuqgeTmTO0NIoaajMXmM@x3XwRsRZds8YB3TxDUbYv/CaKTJ2XVplqvoeirVXPXVK2NXA5NkfsojtKNusKibts82m2Oe/aBYW3ZgfKvhYVufm9Xbbop9wIDvO3tOc3JuL661zM1th4wbdbEMyP19MPkkjVKC0mGR8uhhCoefrV2O@bJNsy6gOy7/hqPCnX@q778vXOe5dDmfxQyHH36H/Aw "Clean – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 56 bytes
```
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
```
[Try it online!](https://tio.run/##VcnRCoIwFIDh@54ihKDEhnoRiNkeRLzY5hEl2ZGdDVvqs68IuvDqh/8zTvrQVeH6oGWuipKYQqftsqp1vs9VHXPBGH8nMc@@LRKeNmzQLbzO6nK6bVuYjl0dPcFLFKaNmOqFoebwu3maZjQJBdh6IvB7JTTGW5RoezAe3V5tP2g5OhgHDXuRoyCb/1/4AA "Ruby – Try It Online")
Preliminary naive version, will be golfed.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-x`, 14 bytes
```
®rT4 c Ä u6Ãä<
```
[Try it online!](https://ethproductions.github.io/japt/?v=1.4.6&code=rnJUNCBjIMQgdTbD5Dw=&input=WyJCIiwiTCIsIkEiLCJTIiwiVCIsIjIiXQoteA==)
Port of [this](https://codegolf.stackexchange.com/a/176498/71434) Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
```
®rT4 c Ä u6Ãä<    :
®          Ã      :Map each character through:
 rT4              : Replace 0 with 4
     c            : Get the char-code
       Ä          : Increment it
         u6       : Modulo 6
            ä<    :Replace with 1 if you had to move right, 0 otherwise
                  :Implicitly sum and output
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
```
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
```
[Try it online!](https://tio.run/##bVHBbgIhFDzrVxCTJhDZLZqmqbulpum5XjwaDyygoits4K0JMX77ltVNenEOvPBmHszAUVxE5hptj@rUNW1VG4lkLUJAv8JYdB2PUcJABBCQirGg/U5IjVZJgAYMmkQii@VB@M0WSVLe@dt4dK/DAStkEUcdZF/XXi74gkrOyp3zuN@rAoiccvGJBcdZpqZYvb59cD5bzgtGyMs7Wc4KVnoNrbdIlreufGbz4oxC55QCr8Ebu09@hN8HkjyP@qse3b6HijuzYds8NLUBPKETQv6j9VjHAPqcuxbyJs1BbbHNLU5zObifFPfbexExIUPkR@zHeuu6k46VE17ROWMzEZr0ek7FEHSkwXkfwVUODtpH11I4GFvVra6N1bRKnwFzumB/ "Java (OpenJDK 8) – Try It Online")
**Explained**
```
t -> {                          // Lambda taking a char array as input
    int a=9,                    // Initialise last column value
        c=0;                    // Initialise frustration count
    for(int d:t)                // Loop through all chars in title
        c+=                     // increment the frustration count if...
          a<                    // The last column is smaller than the current column
            (a=                 // Set last column to current column
              (--d+             // Decrement ascii value of char
                  (d/48==1      // If ascii decremented ascii value is between 48 and 95
                    ?2:0)       // increment by 2 (1 total) or 0 (-1 total)
                )%6)            // Mod 6 to retrieve column index
            ?1:0;               // Increment if to right hand side
    return c;                   // return calculated frustration count
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~12~~ 11 bytes
-1 byte thanks to @Kevin Cruijssen
```
¾4:Ç>6%¥1@O
```
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation: 
```
¾4:Ç>6%¥1@O   //full program
¾4:           //replace all '0's with '4's
   Ç          //get ASCII code points
    >         //increment
     6%       //modulo 6
       ¥      //get deltas
        1@    //is >= 1
          O   //sum
```
[Try it online!](https://tio.run/##yy9OTMpM/f//0D4Tq8Ptdmaqh5YaOvj//@/k4xgcYgQA "05AB1E – Try It Online")
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), ~~32 31~~ 28 bytes
```
+/>':6!(,/"a10"+!'26 9 1)?0+
```
[Try it online!](https://tio.run/##HYzRCoIwFEDf@wq7BCoWTiOpXagPEcEtZ4pji22CI@rXF/p4zoEzndRLhdDTLL/HtNonxxxYQSDbx2UV3aIifZAsOPo51P5naB8t2OoJk7Zno8QFPZq0@e5cDZPwXDPTAZ6blUtCCmbf7Cl0560VHrDagtXGeKe5doMwXs@A1827YVRczkKOSgBeNscls65cl@EP "K (ngn/k) – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 46 bytes
```
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);1\1
```
[Try it online!](https://tio.run/##XcIxDsIwDADA3e8oVQEVxR2QUB7ABxgZklBLjYjiynEHvz7snE5Ic439ND1Df4WC88MFnO9/4QZ@GIcLjMFPeD17fGPvX7LEUVZYnMPY9vghXq01MmgsYsqJdSMxPkC3XFM5qORKkEpsuvwA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
T`l1-90`1-61-61-61-61-61-6
```
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
```
.
;$&$*
```
Convert each column number to unary.
```
&`;(1+);1\1
```
Count the number of columns that are followed by a larger (i.e. rightwards) column. The `&`` allows the matches to overlap.
[Answer]
# [Python 2](https://docs.python.org/2/), 84 bytes
```
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
```
[Try it online!](https://tio.run/##FY69bsMwEIPn9im0BCc1MiB7CBA3yYsYHuTqDP9BZ9zJgzr01d1oIcgPBME9p4lic54BRzVqsevzZtrlqYmDls715qrBwaPYB7RgvpqqNpfbN2M6OOrltb4bf9WGUYvxMZSRrm57uxhzjsRK1BxVByvmgTwHsAoa52ovu/9BClkEc4FCzDnRQGlCznQUlqY5DtuB2xyx5GHzkpri7q5o/q2hbz8/dp5jUmKheoF9HzDnPw "Python 2 – Try It Online")
[Answer]
# Mathematica, 102 bytes
```
Differences[Last@@Join[Alphabet[],ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
```
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
[Answer]
# PHP, ~~74 81~~ 77 bytes
```
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/b886a69f5aefe0e55bef6fad8102dcfa9d195b4c).
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~82 79~~  77 bytes
```
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
```
[Try it online!](https://tio.run/##bY/BaoQwFEX3fkUQLHEcIQ7tUCaNw/xB920XMcYa6uQN78WFiN9u08WUQn3Le8698Ez5acy6gjTc5bMrlHs5igdXPz6fq9OTdJk6yqXjpte4o3zuADkoIXdFQRIKZXhMa8Ppraw@8lyCArmsOPqLb1/R@XBvsjlh8W4/WcfTjFhZs6x99@me9h2n2E2WJImUXbXz/F74O5V@2akBjW0a5X/wIESl6aaNhXYispsSAeIUoIHQW5xg3JRC73wzjHZwfnulGTSFwy@yYUTPRHxg/QY "C (gcc) – Try It Online")
This function will only support lowercase inputs
---
# Ungolfed and commented:
```
o; //Used for output
c(i){             //Calculates the column of given character
     i+=          //Correct i to get the correct column
        i<60      //If i is a digit...
        & i>48   //... but not '0'
        ?1           //Then move it one column on the right
        :5;          //Else move it five columns on the right
     i%=6;        //Get the column number
}
f(char*s){                        // The actual "frustrating" function
          for(                    //Loop for each character
              o=0;                //reinitialize output
              *++s;               //move to next character / while this is not '\0'
              o+=c(*s)>c(s[-1])  //Increment if current character is on the right of the previous one
             );
           o=o;                   // Outputs result
}
```
---
If my function is allowed to accept wide character strings, it can be reduced to **76 bytes** with:
```
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
```
[Try it online!](https://tio.run/##dY9BS8QwEIXv/RWhUEm3W0gXXWRjKt73IHhUD2ma7g7WzJJJkVL622sEFcHdOb73fQ/GlAdjlgWl4ZBPUCi424orqK9v76vdjYRMbeXccXBhRfnUoeeohFwVBUkslOExrQ2n57J6zXOJCuW8@ME9uPbRR@lbZFPC4n2cvrKO79PsiZU1y9oXl65p3XGKcjInSazZuwbHf5S/W/v0zY4Nat@mkf7fboSoNJ20sdiORPY8Rej9GLDBcLR@xOE8FY7gmn6wPbgLO02vKWx@OxsG75iIXyyf "C (gcc) – Try It Online")
This version just accept input as `int*` instead of `char*`
---
# Edits:
* Golfed 3 bytes in the calculation of the column (function `c`)
* Golfed 2 bytes thanks to ceilingcat
]