Syllables in a Number Make a program/function which takes in an integer from 0 to 999999999999 (inclusive) as input and returns how many syllables it has when spoken in English. Make your code short.

Specification


A billion is a thousand million, a trillion is a million million, etc.
A million has three syllables -- it's mill-ee-on, as opposed to mill-yon. Pronounce all -illions like this.
Numbers like 1115 are 'one thousand, one hundred and fifteen'. The 'and' counts as a syllable.
0 is zero. That's two syllables.


I know the specification seems mishmash in terms of which standards are used (British or American, mainly) -- it's what I and everyone I know use. I would change it so it's consistent, but someone's already answered...

Test Cases

&gt; 0
2
(zero)

&gt; 100
3
(one hundred)

&gt; 1000001
6
(one million and one)

&gt; 1001000001
10
(one billon, one million and one)

&gt; 7
2
(seven)

&gt; 28
3
(twenty-eight)

&gt; 78
4
(seventy-eight)

&gt; 11
3
(eleven)

&gt; 1111
10
(one thousand, one hundred and eleven)

&gt; 999999999999
36
(nine hundred and ninety-nine billion, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine)
Python 2, 232 bytes



def f(a):o=map(int,format(a,",").split(","));print(a%100&gt;0)*(a&gt;1000)+sum((k%100&gt;0)*(k/100&gt;0)for k in o[:-1])+sum((k&gt;99)*2+`k`.count('7')+(k/10%10&gt;0)+3-`k+1000`.count('0')for k in o)+sum((0&lt;o[~k])*(5-k)*k/2for k in range(len(o)))or 2


Try it online!

This still has some potential for golfing, maybe in a lambda.
The function splits the input into groups of three digits, each of which have a certain number of syllables. Luckily, every digit is 1 syllable except for 7. Every tens-place adds an extra 1 syllable to the number of syllables of the digit except for 1, which adds 0 (-teen or ten).

Ungolfed:

def f(k):
    a=k
    if a==0:return 2
    o=[]
    while a&gt;0:
        o.append(a%1000)
        a/=1000
    o=o[::-1]
    return \
int(o[-1]%100&gt;0 and len(o)&gt;1)        +len('+1 if first group of three have "and"'[0:0])+\
sum(\
  [int(k%100&gt;0 and k/100&gt;0)        +len('+1 if rest have "and"'[0:0])\ 
for k in o[:-1]])+    
sum(\
  [int(k&gt;99)*2                      +len('have "hundred"'[0:0])\
  +str(k).count('7')               +len('+1 for "se-ven"'[0:0])\
  +(k/10%10&gt;0)                    +len('+1 for "-ty" e.g. nine-ty'[0:0])\
  +3-str(k+1000).count('0')        +len('+1 for each number'[0:0])\
for k in o])+\
sum(\
  [int(o[-(k+1)]&gt;0)*([0,2,3,3][k])  +len('add 2 if "thousand", add 3 if "million", add 3 if "billion"'[0:0])\
for k in range(len(o))])


-12 bytes thanks to @Mr.Xcoder