Count rotary dial pulses in a phone number (including letters) In your grandparents' day, dialing a phone number was done with a rotary dial like this:



To dial each digit, put your finger in the corresponding hole, pull it over to the finger stop, and release it.  A mechanism will cause the dial to spin back to its resting position, and the phone will disconnect and reconnect a circuit a specified number of times, making audible clicks.

Dialing the digit N requires N such &ldquo;pulses&rdquo;, except for N=0 which is ten pulses.

Rotary phones have the property that large digits (8, 9, 0) take longer to dial than small digits (1, 2, 3).  This was an important consideration in drawing up early area code maps, and why New York City with its heavy population (and phone line) density got 212 (only 5 pulses), while while 907 (26 pulses) went to sparsely-inhabited Alaska.  Of course, this all became irrelevant when touch-tone dialing became popular.

The challenge

Write, in as few bytes as possible, a program or function that takes as input a string (or sequence of characters) containing a telephone number, and outputs its number of rotary dial pulses.  These are to be counted as follows:

Digits


Digits 1-9 count as that number of pulses.
Digit 0 counts as 10 pulses.


Letters

Note that digits 2-9 on the dial have letters of the Latin alphabet associated with them.  These were originally intended for named exchanges, but were latter re-appropriated for phonewords, and for text message input systems.

You must support having letters in your phone numbers, using the E.161 assignment of letters to digits:


A, B, C = 2
D, E, F = 3
G, H, I = 4
J, K, L = 5
M, N, O = 6
P, Q, R, S = 7
T, U, V = 8
W, X, Y, Z = 9


You may assume that the input has already been case-folded, to either upper or lower case.

Other characters

You must allow arbitrary use of the characters ()+-./ and space as formatting separators.  You may chose to allow any non-alphanumeric character for this purpose, if it's easier to implement.

These characters do not contribute to the pulse count.

Example code

A non-golfed lookup table and function in Python:

PULSES = {
    '1': 1,
    '2': 2, 'A': 2, 'B': 2, 'C': 2,
    '3': 3, 'D': 3, 'E': 3, 'F': 3,
    '4': 4, 'G': 4, 'H': 4, 'I': 4,
    '5': 5, 'J': 5, 'K': 5, 'L': 5,
    '6': 6, 'M': 6, 'N': 6, 'O': 6,
    '7': 7, 'P': 7, 'Q': 7, 'R': 7, 'S': 7,
    '8': 8, 'T': 8, 'U': 8, 'V': 8,
    '9': 9, 'W': 9, 'X': 9, 'Y': 9, 'Z': 9,
    '0': 10
}

def pulse_count(phone_num):
    return sum(PULSES.get(digit, 0) for digit in phone_num)


Example input and output


911 &rarr; 11
867-5309 &rarr; 48
713 555 0123 &rarr; 42
+1 (212) PE6-5000 &rarr; 57
1-800-FLOWERS &rarr; 69
PUZZLES &rarr; 48
05AB1E, 19 18 17 15 bytes

AÁ0ªā6+žq÷9š‡þO


Try it online!

This is the first answer to use π. Why use π, you might ask? Well, the letters are associated with 22233344455566677778889999, in order. Notice how most digits repeat 3 times, but 7 repeats 4 times. You could say that each digit repeats (3+1/7) times, on average. I wonder if there’s any number that’s approximately 3+1/7 and takes fewer bytes than 22/7…

This only gives 4 7s, not 4 9s, so we still need to handle Z as a special case.

A               # alphabet (abcdefghijklmnopqrstuvwxyz)
 Á              # rotate right (zabcdefghijklmnopqrstuvwxy)
  0ª            # append 0 (zabcdefghijklmnopqrstuvwxy0)

ā6+             # range [7..33]
   žq÷          # divide by π (22233344455566677778889991010)
      9š        # prepend 9 (922233344455566677778889991010)

‡               # transliterate the implicit input with the two lists above
                # this replaces z → 9, a → 2, … y → 9, 0 → 10
 þ              # remove all non-digits
  O             # sum