[Question]
  [
# Goal
Write a program or function that translates a numerical telephone number into text that makes it easy to say. When digits are repeated, they should be read as "double n" or "triple n".
# Requirements
## Input
A string of digits.
* Assume all characters are digits from 0 to 9.
* Assume the string contains at least one character.
## Output
Words, separated by spaces, of how these digits can be read out loud.
* Translate digits to words:
0 "oh"  
1 "one"  
2 "two"  
3 "three"  
4 "four"  
5 "five"  
6 "six"  
7 "seven"  
8 "eight"  
9 "nine"
* When the same digit is repeated twice in a row, write "double *number*".
* When the same digit is repeated thrice in a row, write "triple *number*".
* When the same digit is repeated four or more times, write "double *number*" for the first two digits and evaluate the rest of the string.
* There is exactly one space character between each word. A single leading or trailing space is acceptable.
* Output is not case sensitive.
# Scoring
Source code with the least bytes.
# Test Cases
```
input        output
-------------------
0123         oh one two three
4554554      four double five four double five four
000          triple oh
00000        double oh triple oh
66667888     double six double six seven triple eight
19999999179  one double nine double nine triple nine one seven nine
```
  
[Answer]
# 8088 Assembly, IBM PC DOS, ~~164~~ ~~159~~ ~~156~~ 155 bytes
**Binary:**
```
00000000: d1ee 8a0c 03f1 53fd ac3a d075 0343 e2f7  ......S..:.u.C..
00000010: 85db 741c 5f8a d043 f6c3 0174 0a57 bd64  ..t._..C...t.W.d
00000020: 0155 83eb 0374 0957 bd5d 0155 4b4b 75f7  .U...t.W.].UKKu.
00000030: 8ad0 2c2f 7213 518a f0b0 24b1 31bf 6a01  ..,/r.Q...$.1.j.
00000040: fcf2 aefe ce75 fa59 57e2 bc5a 85d2 740c  .....u.YW..Z..t.
00000050: b409 cd21 b220 b402 cd21 ebef c364 6f75  ...!. ...!...dou
00000060: 626c 6524 7472 6970 6c65 246f 6824 6f6e  ble$triple$oh$on
00000070: 6524 7477 6f24 7468 7265 6524 666f 7572  e$two$three$four
00000080: 2466 6976 6524 7369 7824 7365 7665 6e24  $five$six$seven$
00000090: 6569 6768 7424 6e69 6e65 24              eight$nine$
```
Build and test executable using `xxd -r` from above, or download [PHONE.COM](https://stage.stonedrop.com/ppcg/PHONE.COM).
**Unassembled listing:**
```
D1 EE       SHR  SI, 1              ; point SI to DOS PSP (80H) for input string
8A 0C       MOV  CL, BYTE PTR[SI]   ; load input string length into CX
03 F1       ADD  SI, CX             ; move SI to end of input 
53          PUSH BX                 ; push a 0 to signal end of output stack 
        CHAR_LOOP:
FD          STD                     ; set LODS direction to reverse 
AC          LODSB                   ; load next char from [SI] into AL, advance SI 
3A D0       CMP  DL, AL             ; is it same as previous char? 
75 03       JNZ  NEW_CHAR           ; if not, it's a different char 
43          INC  BX                 ; otherwise it's a run, so increment run length
E2 F7       LOOP CHAR_LOOP          ; move on to next char 
        NEW_CHAR: 
85 DB       TEST BX, BX             ; is there a run greater than 0? 
74 1C       JZ   GET_WORD           ; if not, look up digit name 
5F          POP  DI                 ; get name for the current digit 
8A D0       MOV  DL, AL             ; save current char in DL 
43          INC  BX                 ; adjust run count (BX=1 means run of 2, etc)
F6 C3 01    TEST BL, 1              ; is odd? if so, it's a triple
74 0A       JZ   IS_DBL             ; is even, so is a double 
57          PUSH DI                 ; push number string ("one", etc) to stack
BD 0164     MOV  BP, OFFSET T       ; load "triple" string 
55          PUSH BP                 ; push to stack 
83 EB 03    SUB  BX, 3              ; decrement run count by 3 
74 09       JZ   GET_WORD           ; if end of run, move to next input char 
        IS_DBL: 
57          PUSH DI                 ; push number string to stack
BD 015D     MOV  BP, OFFSET D       ; load "double" string 
55          PUSH BP                 ; push to stack 
4B          DEC  BX                 ; decrement by 2
4B          DEC  BX
75 F7       JNZ  IS_DBL             ; if not end of run, loop double again 
        GET_WORD: 
8A D0       MOV  DL, AL             ; save current char into DL
2C 2F       SUB  AL, '0'-1          ; convert ASCII char to 1-based index 
72 13       JB   NOT_FOUND          ; if not a valid char, move to next
51          PUSH CX                 ; save outer loop counter 
8A F0       MOV  DH, AL             ; DH is the index to find, use as scan loop counter
B0 24       MOV  AL, '$'            ; word string is $ delimited
B1 31       MOV  CL, 031H           ; search through length of word data (49 bytes)
BF 016A     MOV  DI, OFFSET W       ; reset word data pointer to beginning
FC          CLD                     ; set DF to scan forward for SCAS 
        SCAN_LOOP: 
F2/ AE      REPNZ SCASB             ; search until delimiter '$' is found in [DI]
FE CE       DEC  DH                 ; delimiter found, decrement counter 
75 FA       JNZ  SCAN_LOOP          ; if counter reached 0, index has been found 
59          POP  CX                 ; restore outer loop position
57          PUSH DI                 ; push string on stack 
        NOT_FOUND:
E2 BC       LOOP CHAR_LOOP          ; move to next char in input 
        OUTPUT_STACK: 
5A          POP  DX                 ; get string from top of stack 
85 D2       TEST DX, DX             ; it is the last? 
74 0C       JZ   EXIT               ; if so, exit 
B4 09       MOV  AH, 09H            ; DOS display string function 
CD 21       INT  21H                ; write string to console 
B2 20       MOV  DL, ' '            ; load space delimiter 
B4 02       MOV  AH, 02H            ; DOS display char function 
CD 21       INT  21H                ; write char to console 
EB EF       JMP  OUTPUT_STACK       ; continue looping 
        EXIT: 
C3          RET                     ; return to DOS 
                 
D   DB "double$" 
T   DB "triple"
W   DB "$oh$","one$","two$","three$","four$","five$","six$","seven$","eight$","nine$" 
```
**TL;DR:**
The input string is read right to left to make it easier to find a triple. The output is pushed onto the [x86 stack](https://en.wikipedia.org/wiki/Intel_8086#Registers_and_instructions) to simplify reversing out the display order and also facilitate rearranging the "double" and "triple" words to precede the digit's name.
If the next digit is different than the last, the name is looked up in the list of words and pushed on to the stack. Since there's no formal concept of an "indexed array of variable-length strings" in machine code, the list of words is scanned `i` (the word's index) number of times for the string delimiter (`$`) to find the corresponding word. Helpfully, x86 does have a pair of short instructions (`REPNZ SCASB` which is similar to `memchr()` in C), that simplifies this (thanks [CISC](https://en.wikipedia.org/wiki/Complex_instruction_set_computer)!).
If the digit is the same as the previous one, the counter for the length of a "run" is incremented and continues looping leftward on the input. Once the run is over, the digit's name is taken from the stack since it will need to placed after the "double" or "triple" for each grouping. If the length of the run is odd (and run length is `> 1`), the digit's name followed by the string "triple" is pushed to the stack and the run length is reduced by 3. Since the run length will now be even, the step is repeated for "double" until the run length is 0.
When the input string has reached the end, the stack is dumped out with each saved string written to the screen in reverse order.
**I/O:**
A standalone PC DOS executable, input from command line output to console.
[![enter image description here](https://i.stack.imgur.com/tf3tx.png)](https://i.stack.imgur.com/tf3tx.png)
Download and test [PHONE.COM](https://stage.stonedrop.com/ppcg/PHONE.COM).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~53~~ ~~52~~ ~~51~~ ~~50~~ 49 bytes
```
γε€T2äθ¬MÊi¨₃1ǝR]˜“Šç€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š‹¶½¿“#sè¸»
```
[Try it online!](https://tio.run/##AYEAfv9vc2FiaWX//86zzrXigqxUMsOkzrjCrE3DimnCqOKCgzHHnVJdy5zigJzFoMOn4oKswrXigJrigKLigJ7DreKAoMOsy4bDiMWSxaHDr8K/xbjCr8KlxaDigLnCtsK9wr/igJwjc8OowrjCu///NjY2Njc4ODg4OP8tLW5vLWxhenk "05AB1E – Try It Online")
Explanation:
```
γ                      # split input in groups of consecutive equal digits
 ε              ]      # for each group
  €T                   #  add a 10 before each digit (66 -> [10, 6, 10, 6])
    2äθ                #  keep only the second half of that list
       ¬MÊi     ]      #  if the first element is not the maximum
           ¨           #   drop the last element
            ₃1ǝ        #   replace the second element with 95
               R       #   reverse the list
˜                      # flatten
 “...“                 # compressed string: "oh one two ... nine double triple"
      #                # split on spaces
       sè              # index (wraps around, so 95 yields "triple")
         ¸»            # join with spaces
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~61~~ ~~56~~ ~~53~~ ~~52~~ 51 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
γvyDg;LàäRv… ‹¶½¿#ygè“Šç€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š“#yè])áðý
```
-9 bytes thanks to *@Grimy*.
[Try it online](https://tio.run/##AXUAiv9vc2FiaWX//86zdnlEZztMw6DDpFJ24oCmIOKAucK2wr3CvyN5Z8Oo4oCcxaDDp@KCrMK14oCa4oCi4oCew63igKDDrMuGw4jFksWhw6/Cv8W4wq/CpcWg4oCcI3nDqF0pw6HDsMO9//8xOTk5OTk5OTE3Nzk) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/3Obyypd0q19Di84vCSo7FHDMoVHDTsPbTu099B@5cr0wyseNcw5uuDw8kdNaw5tfdQw61HDokcN8w6vfdSw4PCa022HO45OOrrw8PpD@4/uOLT@0NKjC4DqlSsPr6it1Ty88PCGw3v/6/w3MDQy5jIxNQUhLgMDAy4zIDC3sLDgMrSEAENzc0sA).
**Explanation:**
```
γ               # Split the (implicit) input into substrings of equal adjacent characters
                #  i.e. "199999991779" → ["1","9999999","1","77","9"]
 v              # Loop over each substring `y`:
   Dg           #  Get the length of a copy of the substring
     ;          #  Halve it
      L         #  Create a list in the range [1, length/2], where odd lengths are
                #  automatically truncated/floored
                #   i.e. "1" (length=1) → 0.5 → [1,0]
                #   i.e. "9999999" (length=7) → 3.5 → [1,2,3]
       à        #  Pop and push the maximum of this list
  y     ä       #  Divide the string into that many parts
                #   → ["1"]
                #   → ["999","99","99"]
         R      #  Reverse the list
                #   → ["99","99","999"]
  v             # Inner loop over each item `y`:
   … ‹¶½¿       #  Push dictionary word: "  double triple"
         #      #  Split it on spaces: ["","","double","triple"]
          yg    #  Get the length of the current item `y`
            è   #  And use it to (0-based) index into the list
   “Šç€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š“
                #  Push dictionary string "oh two three four five six seven eight nine"
     #          #  Split it on spaces: ["oh","two","three",...,"nine"]
      yè        #  Use `y` to index into the string-list (with automatic wrap-around,
                #  so since there are 10 words, it basically indexes with a single digit
                #  due to an implicit modulo-10)
                #   i.e. "77" → "seven"
 ]              # Close both loops
  )             # Wrap all values on the stack into a list
   á            # Only keep letters, which removes the empty strings from the list
    ðý          # And join the list on spaces
                # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `… ‹¶½¿` is `" double triple"` and `“Šç€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š“` is `"oh two three four five six seven eight nine"`.
[Answer]
# [QuadR](https://github.com/abrudz/QuadRS), 137 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Title case with a leading space.
```
∊¯2↑¨@(∊∘⎕A)⍵
(.)\1*
{⍺←(,¨⎕D)⎕R('OhOneTwoThreeFourFiveSixSevenEightNine'(∊⊂⊣)⎕A)⋄' '∊w←⍺,⊃⍵:⍬⋄1=≢⍵:⍺⍵⋄3=≢⍵:'Triple',w⋄'Double',w,∇2↓⍵}⍵M
```
[Try it online!](https://tio.run/##KyxNTCn6//9RR9eh9UaP2iYeWuGgAeQ86pjxqG@qo@aj3q1cGnqaMYZaXNWPenc9apugoXNoBVDKRRNIBGmo@2f456WGlOeHZBSlprrllxa5ZZalBmdWBKeWpea5ZqZnlPhl5qWqg83sanrUtVgTYm53i7qCOlCwHGgk0GCdR13NQLusHvWuAUoZ2j7qXATh7gJSQBFjmIh6SFFmQU6quk45yAiX/NIkMEfnUUc70PmTgUpqgdj3/39DSwgwNLfkMjA0MuYyMTUFIS4DAwMuMyAwt7Cw4EJSBQA "QuadR – Try It Online")
`∊` **ϵ**nlist (flatten)  
`¯2↑¨` take the last two characters (padding on left with a space) of each characters  
`@` at positions where  
`(∊∘⎕A)` characters are members of the uppercase **A**lphabet  
`⍵` in the result of the below PCRE Replace operation…
`(.)` any character  
`\1` followed by itself  
`*` zero or more times, is replaced by the result of the following…
`{…}⍵M` "dfn"; `⍵` is the **M**atch of the above pattern
 `('OhOneTwoThreeFourFiveSixSevenEightNine'(`…`)⎕A)` apply the following anonymous tacit function with the long string and the uppercase **A**lphabet as left arguments:
 `∊` membership (of letters in the long string in the uppercase alphabet)
 `⊂` partitions (with a new partition beginning whenever is-a-member
 `⊣` the left argument (i.e. the long string)
`(`…`)⎕R` PCRE **R**eplace the following patterns with those words:
 `⎕D` the digits 0 through 9
 `,¨` treat each as a separate pattern
`⍺←` assign this replacement function to `⍺` (for **a**lphabetise)
`⋄` then,
`⊃⍵` the first character of the match
`,` as a string
`⍺` apply `⍺` to it
`w←` assign this to `w` (for **word**)
`' '∊`…`:` if space is a member thereof (i.e. if the match was empty):
 `⍬` return nothing (becomes the empty string)
`⋄` else,
`1=≢⍵:` if one equals the tally of characters in the match (i.e. its length):
 `⍺⍵` alphabetise that digit
`⋄` else,
`3=≢⍵:` if three equals the tally of characters in the match (i.e. its length):
 `'Triple',w` prepend "Triple" to the **w**ord
`⋄` else,
`2↓⍵` drop to digits from the match
`∇` recurse on that
`w,` prepend the word
`'Double',` prepend "Double"
[Answer]
# JavaScript (ES6), ~~161 160 152~~ 144 bytes
The output includes a single leading space.
```
s=>[n=>' '+'oh/one/two/three/four/five/six/seven/eight/nine'.split`/`[n],'$1 double$2','triple$2'].map(r=>s=s.replace(/(\S*)( \S+)\2|\d/g,r))&&s
```
[Try it online!](https://tio.run/##bVDLboMwELz3K6woik1DWaBNQw7wEzmGSKGwPCpqI@zQHvrv1DakSlFXHMZoZ3Zm3rMhk3nfdOqJiwLHMh5lnJx4nFBCt1TUIDiC@hSg6h4RSnHtoWwGBNl8gcQBOWBT1Qp4w5F6smsbdYHLiZ9dug5IIa5vLa5D6lKlr1h49j6yjvVxImPp9di1WY4MWHp8dBhJj1snDb/TAiq3d5zNRo654FK06LWiYiVb@UH4vHIcchsAImqibRJtk1ibDwvKy25nvl@Wppggszti8vz/Yynk@/79aSM0xdIWlruvevZRFN0IeneW19XdQ9viTceWuZQKDtME@4NVM5F13lnDNP8Hz1IWm73pgHmOPw "JavaScript (Node.js) – Try It Online")
or [See the formatted source code](https://tio.run/##bVHbboMwDH3vV1hVVWDtMLB1pQ/dT/SxVCoDc5lYgghle9i/MyfA1KE5sWRHx8c@znvcxSppyrp9FDKlPjv2Co6vC4AzO4DgBCw@G7BkgVIQtp8S26IhwkzeGszKjlCVX6ioI4FU5kWLohRkuaquyvaK17O4bA2btfIhlbe3ilaBNT613NzknF7Y3Y@4tpthBgAeBpTbUF3FCdloR6cHx4botHGi4DtKMd9C4zBS@3oNqk@kULIit5K5ndlLzw@elo4DkyGCLIBlAMsAI2MxK3ne7fT9reISLXQcHLTe/x/mRJ7n3bfWRINYHmGOfWHbh2E4FTB2pOfV3odmyxOPWfacyj8M5u8Phk1LZr0jh/6ZP/FIZWKNGxrotP8B)
## How?
The conversion is processed in three steps:
1. replace each digit with the corresponding English word, preceded by a space
2. replace each pattern `"X X"` with `"double X"`
3. replace each pattern `"double X X"` with `"triple X"`
To save bytes, we use the same regular expression for all steps:
```
/(\S*)( \S+)\2|\d/g
```
which works as follows:
```
(\S*)  -> 1st capturing group: any word, or nothing at all
( \S+) -> 2nd capturing group: a space, followed by a word
\2     -> a copy of the 2nd capturing group
|\d    -> or try to capture a digit instead (for step 1)
```
At step 1, we use a callback function that picks the correct word from a lookup table:
* `"799999"` → `" seven nine nine nine nine nine"`
At step 2, we replace with `"$1 double$2"`:
* `" (seven)( nine)( nine)"` → `" seven double nine"`
* `"( nine)( nine) nine"` → `" double nine nine"`
At step 3, we replace with `"triple$2"`:
* `" (double)( nine)( nine)"` → `" triple nine"`
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 115 bytes
```
{Switch[L=Tr[1^{##}],1," ",3," triple ",_," double "],If[#<1,"oh",IntegerName@#],If[L>3,#0@##3,""]}&@@@Split@#<>""&
```
[Try it online!](https://tio.run/##VY1NC4JAEIbv/orYAU8TafYllOxVkCjsJhZmay5kiqx0WPa322x1iQde5p13PppC1aIplCyLsdqNOn1JVdZZsjv1mX/WACZHH9mEYUCqetk9BJkLmVs7XK3JMa4y2NJUWzOMn0rcRb8vGsHhEyVRgOBxALrAcuNyztPuIRWHbcSYOx4HKRQ/9PKpMphGFa25M64d7dHnOQYGHb3AJfFT2/CQsMUKv6xxY7EtH8M/fApD45jxDQ "Wolfram Language (Mathematica) – Try It Online")
Takes a list of digits as input. Output includes a leading space.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 56 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ÇÖ◘⌡¿╒ô╞Γ▓8m☻t7♦3├(Ä⌂≤(┬Ω☻9▲ç╕C╞⌡òσ╗─╣╥─☻╪▼⌡5■ÿ,(┬¥?☺÷•±
```
[Run and debug it](https://staxlang.xyz/#p=809908f5a8d593c6e2b2386d0274370433c3288e7ff328c2ea02391e87b843c6f595e5bbc4b9d2c402d81ff535fe982c28c29d3f01f607f1&i=%2201234%22%0A%224554554%22%0A%22000%22%0A%2266667888%22%0A%2219999999179%22%0A%2200000%22&a=1&m=2)
[Answer]
# [Python 2](https://docs.python.org/2/), ~~171~~ ~~169~~ 168 bytes
```
s=input()
while s:c=s[0];n=(s[1:2]==c)+(s[:3]==c*3!=s[1:4]);print'   eellpbiurotd'[-n:0:-2]+'oh one two three four five six seven eight nine'.split()[int(c)],;s=s[1+n:]
```
[Try it online!](https://tio.run/##JY/NboMwEITvfootF0NJKgOhIUZ@EmRVLVliS2iNbJOfp6emHa1Wn/awM7O8onFUb6O7osqybAvK0rLGvGAPY2eEIEcVBqF7UnkYKllrpcaiTCybHd@bN7XfT7roF28pcgBAnOflx67exSsfjiSFPNa65M6AI4T4cBCNR4TJrR4me08@9gkB70iA9mYikCXkH2GZbcoypL/5WOhDH3azkqTeUljGJufhCyyB/6Yb5m0hGeATR9j7MPgLtHFR1Q1n/NS2@yQSQqT9mXTuui5hdflXdb7wXw "Python 2 – Try It Online")
-1 byte, thanks to Jitse
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 111 bytes
```
s/(\d)\1/ double$1/g;s/\w+(\d)\1/triple$1/g;s/\d/' '.qw(oh one two three four five six seven eigth nine)[$&]/ge
```
[Try it online!](https://tio.run/##RYlBDoIwEADvfcUeiECMtlWREp8iXgxLaUK6tS3g660STZzMacahH6uUAi/armwlh46m@4iZ5PoSeLtsfz164/654znk@8dS0ABkEeJCEAePCD1NHnozIwTzhIAzWkCj4wDWWCyv2ebGNaYk5OHITlW1yoQQ7PyhVkox2XyRdbMOIV7koiEb0s69AQ "Perl 5 – Try It Online")
Explanation:
```
s/(\d)\1/ double$1/g; # Replace non-overlapping double digits with " double<digit>"
s/\w+(\d)\1/triple$1/g; # Replace remaining double digits preceded by "double" with "triple<digit>"
s/\d/' '.qw(oh one two three four five six seven eigth nine)[$&]/ge # Replace digits with " <word>"
```
[Answer]
# [Scala](http://www.scala-lang.org/), 213 bytes
Got it. Somehow the recursive version I was trying to build was strongly more verbose-y than this one (still recursive though, but only in one case). Function `f` takes as an input string the phone number and outputs its phonetics with a trailing whitespace.
```
var u="oh one two three four five six seven eight nine" split " "
"(.)\\1*".r.replaceAllIn(s,x=>{var o=x.matched
var k=u(o(0)-48)+" "
o.length match{case 3=>"triple "+k
case 1=>k
case _=>"double "+k+f(o drop 2)}})
```
[Try it online!](https://tio.run/##bVHJboMwEL37K0Y@maYlkKUhlYiUYw89tUekisAQaFwbYZMiIb6dYvAhDR1Z8qzvzaKSmMe9PH1houEtLgRgo1GkCo5l2RKSYgYZUy/vuirE2bF/2PbXuII6pDIHKRD0jwSdV4iQybqCrLgiqKIBhVccIItzrkEUAimokhcaKFBCmetEkf9A3cqtsORxgkfOXwVTj014aA2BDBv3O9ZJjikx9iWsmWSe87QJnIXBkC5HcdY5jFltEiuEdXigQ5clR6CLCxl9fniw2ucQTWV9mqKLjElIK1nCyuk6p@8IWS4/UGkwyYqUw7SaC5Yx6vmrNTWsKpc1T@GEEM3Gjyh1bos22615s7pxS7aNcVn/Ou7RPM@bIdlJZX6f/DzILgiCWYVlMee5UadLWbTxYPeA/n4Sf7ef72FYggUzZ/6jW8xRN3kTkzFHBtL1vw "Scala – Try It Online")
  
**Edit** : -8b thanks to DrY Wit!
# [Scala](http://www.scala-lang.org/), 215 bytes
And here comes the leading whitespace version, two bytes longer for some reason (even with massive refactoring).
```
var u="oh one two three four five six seven eight nine" split " "
"(.)\\1*".r.replaceAllIn(s,x=>{var o=x.matched
var k=u(o(0)-48)
" , double , triple ".split(",")(if(o.length>3){k+=f(o drop 2);1}else o.length-1)+k})
```
[Try it online!](https://tio.run/##bVHBboMwDL3nK6yckrWl0LUr3USlHnfYaTtyoWAKa5YgEjokxLezQJnUlVmR8mzZz/azjiMRder4ibGBtyiXgLVBmWg4FEVDSIIppEw/v5sylyc@/kHTXaISqoCqDJREMN8KTFYiQqqqEtL8gqDzGjRe0FLmp8yAzCVS0IXIDVCghDKHh6H3QJ3SKbEQUYwHIV4l0/M62Dd9AxXUzldk4gwT0vvnoGKKuXyx9jmhMIdEVUeBFtixCguoM/AzOqec5SlTjkB5Mtn@kTfnWWADkJSqgBV/8VoUGuE3Y@Hx2bnlXUvIcvmB2kAcadSksPsaIVnKqOutHimf2R0yVYkEjgjhRICQUn5btN5s@jepG3Qaxx/k@jdwz@a67oRpXF1l98lP1ra@708qxi79gW7g9VYj23Cye0JvdzVvu5vqYEUYyfpD/8Ej54D7vGun3h06kLb7AQ "Scala – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~174~~ ~~169~~ ~~166~~ 159 bytes
```
for(;$s=strspn($argn,$d=$argn[$i],$i++);$s==3?($i+=2)+print'triple ':$s<2?:++$i+print'double ',print[oh,one,two,three,four,five,six,seven,eight,nine][$d].' ');
```
[Try it online!](https://tio.run/##bVHbagMhEH33K4YguMtKc28umyUfst2HNGuiUFTUpIXSb9@OroFQOvgwl3PmcrTSDoejlZYQGoQPHhpoCaCx2XyxZBweNp2CkWC0gPBpIEgnxIhbrdfxPaCIu5ibg97c3j8EXNRd/J/IU2azpyGRHZyyiDNyBLyibbbbbUYhIDfy6uvZ9eIu9IMs1FWGkT/fjTbf7GKLeAbekIla/fEzP/kRN3aNIelqQi7GidNZQpHFOnlIXvmdhtGTu2pUMOXqAdFFTX3jg/NWF6nKad8kp6Wq41RVVRkhzfJYYNAsyso6pQPLi7A99YfFcV9VWB0reV3GU9gayXFRjp/C06fwqC2PKnOUhacDeNKDxzO6lvbdCwNW1kNcWZylgcmbntTpgpv2IuAmZU1@hl8 "PHP – Try It Online")
For each digit at index of `$i` starting from 0:
* If span of the same digit starting from location of `$i` is equal to 3, prints `'triple '` and adds 2 to `$i` so next iteration will have 2 digits jumped over.
* If span of the same digit starting from location of `$i` is equal to or more than 2 but is not 3, prints `'double '` and adds 1 to `$i` so next iteration will have 1 digit jumped over.
* Prints word for the digit and a space.
* `$i++`.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 105 bytes
```
+`(.)\1
=$1
.
 $&
= =
triple
=
double
9
nine
8
eight
7
seven
6
six
5
five
4
four
3
three
2
two
1
one
0
oh
```
[Try it online!](https://tio.run/##JYu9CsIwGAD3e4oOIopQkv6mQ97EQcWvNiCJpGn17WPF44ZbLkpy/prz6XIoj2eN3WlKit0eW1hSdK@nYLmH5bbFgHdeMIh7TImeWVbxdMzuQ8voVqFhDEukJk1RhIr0DmjC9inClLPSVU3Ttj9RStFt9MYY9PBH98MX "Retina 0.8.2 – Try It Online") Outputs a leading space. Explanation: I originally tried a regex that automatically matches 2 or 3 digits but @Arnauld's approach of turned out to be golfier. Explanation:
```
+`(.)\1
=$1
```
Match pairs of identical digits and replace the first with a `=`. Then repeat, so that for an odd number the second last digit is also replaced with a `=`.
```
.
 $&
```
Space the digits (and `=`s) out.
```
= =
triple
```
Handle the case of three identical digits.
```
=
double
9
nine
8
eight
7
seven
6
six
5
five
4
four
3
three
2
two
1
one
0
oh
```
Replace all remaining characters with words.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 59 bytes
```
⁵;`,0;$Ɗ€Ẏ;`Ø0ṭ;-œṣjƭƒV€‘$ị“¡ıc⁴Ṛ⁽]@ɱ2¦Ż©Ẉḷ$Æ!)ɗ[ı8ɱḃ%ċ»Ḳ¤K
```
[Try it online!](https://tio.run/##AYUAev9qZWxsef//4oG1O2AsMDskxorigqzhuo47YMOYMOG5rTstxZPhuaNqxq3GklbigqzigJgk4buL4oCcwqHEsWPigbThuZrigb1dQMmxMsKmxbvCqeG6iOG4tyTDhiEpyZdbxLE4ybHhuIMlxIvCu@G4ssKkS////yIwMTk5OTk5OTkxNzki "Jelly – Try It Online")
A monadic link that takes a string of digit characters as its argument and returns a Jelly string of space-separated words. When called as a full-program, outputs implicitly. 
[Answer]
# T-SQL 2017, 238 bytes
Added some linebreaks to make it readable
```
WHILE''<left(@,1)SELECT @=stuff(@,1,iif(p<4,p,2),'')+
iif(p=1,' ',iif(p=3,' triple ',' double '))
+trim(substring('oh  one  two  threefour five six  seveneightnine',left(@,1)*5,5))
FROM(SELECT~-patindex('%[^'+left(@,1)+']%'+'^',@)p)z
PRINT @
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1090620/telephone-number-in-spoken-words)**
[Answer]
# C++, 382 bytes
It's not superclever, but someone needed to write a C++ version. The recursive function R goes through the input string and counts repeated values. If there are more than 3 repeats, it pretends there were 2 repeats, then rewinds and tries again.
A few more source chars could probably be squeezed out with `#define` major, but I'm sure a better algo could squeeze out more.
```
#include <iostream>
#include <sstream>
using namespace std;
char*n[]={"oh","one","two","three","four","five","six","seven","eight","nine"};
void R(ostream& s,const char*r,char p='x',int c=0){if(*r==p)R(s,r+1,p,c+1);else
{if(c>1){if(c>= 4){s<<"double ";r-=(c-2);}else if(c==3)s<< "triple ";else if(c==2)s<< "double ";
}if(c >0)s<<n[p-'0']<<" ";if(!*r)return;R(s,r+1,*r,1);}}
void check(const char* in, const char* out)
{
    std::stringstream ss;
    R(ss,in);
    if (out == ss.str()) std::cout << "PASS: "; else std::cout << "FAIL! ";
    std::cout << in << "\n< " << out << "\n> " << ss.str() << std::endl;
}
int main(int c,char**argv)
{
    if (argv[1] == std::string("test"))
    {
        check("0123"         ,"oh one two three ");
        check("4554554"      ,"four double five four double five four ");
        check("000"          ,"triple oh ");
        check("00000"        ,"double oh triple oh ");
        check("66667888"     ,"double six double six seven triple eight ");
        check("19999999179"  ,"one double nine double nine triple nine one seven nine ");
    }
    else
    {
        char* v = argv[1];
        R(std::cout,v);
        std::cout << std::endl;
    }
}
```
and verification of test cases:
```
pa-dev01$ ./a.out test
PASS: 0123
< oh one two three
> oh one two three
PASS: 4554554
< four double five four double five four
> four double five four double five four
PASS: 000
< triple oh
> triple oh
PASS: 00000
< double oh triple oh
> double oh triple oh
PASS: 66667888
< double six double six seven triple eight
> double six double six seven triple eight
PASS: 19999999179
< one double nine double nine triple nine one seven nine
> one double nine double nine triple nine one seven nine
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~96~~ 93 bytes
```
{S:g/(.)$0?[$0{}<!$0>]?/{(<triple double>X$)[3-$/.comb]}{+$/??uniname(~$0).words[1]!!'oh'} /}
```
[Try it online!](https://tio.run/##JYndCoIwGEDv9xQThj9E7jPzr2x7iG4C8UJzljB/0CRE1qsvo8Ph3JxBjDLU7YLNGl@wXq@nB7VdhwDPCKwqNQiwnNPVTl9jM0iBq34upWA34mT@nlD33rdlrtYdoZzPXdMVrbA/BBz33Y/VlHm5YVj901KYKn1GsunExJhr1lumYtHgHXx0DIKfCABQuBHFcYy85I8XJb8B8AU "Perl 6 – Try It Online")
This is an anonymous code block that takes a number and returns a string with the numbers in uppercase, e.g. `0123 => oh ONE TWO THREE` with a single trailing space.
This was deleted for a while until I found out how to use captures in a lookahead, but it should be fixed now.
[Answer]
# [Red](http://www.red-lang.org), 242 bytes
```
func[s][b:[copy t skip t]parse s[any[change[b t ahead not t](rejoin["triple "t])|
change b(rejoin["double "t])| skip]]foreach c s[prin either i:
find"0123456789"c[rejoin[pick[:oh:one:two:three:four:five:six:seven:eight:nine]index? i" "]][c]]]
```
[Try it online!](https://tio.run/##TU3LbsMgELz7K1ac2pvdxrG9l/5Dr4gDxkvYJgIEOE2k/rvrJG3k0VzmoZlE0/JJk1SVRVjs7I3MSo4oTYhXKJCPHKGoqFMmyFL7qzRO@wPJcU21Iz2BD2WtvCT6CuylKInjiUAU9fpTPcowPtMpzON/el9XyoZE2jgw60FM7IG4OErAWFn2k6ibt/ddu@/6QRj5txPZHCUGh8ETlu@AxSUitGFOaPlMmPmCmc7kkfjgCnr2pNY1unwACxBKSaOUWm6HBSzcX0T1lLu2vXHj1HW9UfsVXd/3G6sZHmi6QSy/ "Red – Try It Online")
[Answer]
# [Scala](http://www.scala-lang.org/), 253 bytes
```
def g(s:String):String={val t="oh one two three four five six seven eight nine".split(" ")(s(0)-48)
s.length match{case 3=>"triple "+t;case 2=>"double "+t;case 1=>t;case _=>"double "+t+" "+g(s drop 2)}}
s=>"(.)\\1*".r.findAllIn(s).map(g(_)) mkString " "
```
[Try it online!](https://tio.run/##VU9BasMwELzrFYtOUkNMnRbqtNiQY8@9BoJir2y1siSsjRswfrurNi60e9lhZtiZjbWyavHnd6wJasAroWsiHEKAibFRWdDPbzQY15bVuqelQQ2tiKsgfw3Tt51K7jvwDoE@PVA3IIL2lwG0GRGiuULEER2gaTsCZxzyLAZrSHDgUkRxL7ePhWQxs@ha6qBXVHdTrSLCQ1nxFBUsAt/Qyw@3S1zjL@e/XF5WKzr9UzcpYpOKQzP4ADs5zywmg8jk8Zjf8WzItHHNwdpXJ6LMehVEK05SQv9xexHSgWVmIWGyTmjB8/1t8qd9UXAp2bwsXw "Scala – Try It Online")
[Answer]
# Oracle SQL, 578 bytes (in formatted form)
Solution is not concise by any means so posting it in formatted way.
```
with r(s) as
(select x from t
  union all
 select case
           when length(regexp_substr(s, '(.)(\1)+')) = 3 
           then regexp_replace(s, '^...')
           else regexp_replace(s, '^(.)\1|^.')
        end
   from r
  where s is not null)
select listagg(decode(length(r),  2, 'double ',  3, 'triple ') ||
               decode(substr(r, 1, 1), 0, 'oh', to_char(to_date(substr(r, 1, 1), 'j'), 'jsp')), ' ')
               within group (order by rownum)
  from (select regexp_replace(s, lag(s) over (order by length(s)) || '$') r
          from r order by length(s) desc);
```
Test in SQL\*Plus
```
SQL> create table t(x) as select /*'45547777777774'*/ '1999999910079' from dual;
Table created.
SQL> set pages 0
SQL> with r(s) as
  2  (select x from t
  3    union all
  4   select case
  5             when length(regexp_substr(s, '(.)(\1)+')) = 3
  6             then regexp_replace(s, '^...')
  7             else regexp_replace(s, '^(.)\1|^.')
  8          end
  9     from r
 10    where s is not null)
 11  select listagg(decode(length(r),  2, 'double ',  3, 'triple ') ||
 12                 decode(substr(r, 1, 1), 0, 'oh', to_char(to_date(substr(r, 1, 1), 'j'), 'jsp')), ' ')
 13                 within group (order by rownum)
 14    from (select regexp_replace(s, lag(s) over (order by length(s)) || '$') r
 15            from r order by length(s) desc);
one double nine double nine triple nine one double oh seven nine
```
The main trick is that digits converted into words using Oracle format models instead of hard-coded literals "one" ... "nine".
[Answer]
# JavaScript, 142 bytes
```
s=>s.replace(/(.)(\1\1(?!\1)|\1|)/g,t=>(t[2]?' triple ':t[1]?' double ':' ')+'oh one two three four five six seven eight nine'.split` `[t[0]])
```
[Try it online!](https://tio.run/##bZDBboMwDIbvewqvlyTaBqRbVzqJ9kEAqZQayIQSRFK2Q9@dkZBOHZqVgx35/@zfn8VQ6LIXnXmR6oxjlYw62eugx64tSqQhDRjNeMbp4THj7JrxKwvrZ5PsqUnX@YGAmcQtAvkwKbf1WV1OriZA2BNRDSiJYL4UmKZHhEpdeqjEgKDFN2gcUAKKujEghUQS6K4V5gjH1KRRnrOxVFKrFoNW1bSiq4ivX1eMwS3CEJYjHhaSt83Gvl/VJHFL@E3dLv9@LEFRFN2PtiDvXjXL3vcptnEc3wRTr8db23fpfAHPcYdYovhuDr7dOZq1PPn1DHu1P7lHudz2zQNsOf4A "JavaScript (Node.js) – Try It Online")
[Answer]
# (Roblox) [Lua 5.1](https://www.lua.org/), 166 bytes
```
for I,N in('111 triple 11 double 1 '):gmatch'(%d+)(%D+)'do for i,n in('0oh1one2two3three4four5five6six7seven8eight9nine'):gmatch'(.)(%l+)'do s=s:gsub(i*I,N..n)end end
```
*Ensure `s` is a predefined string value populated only with digits; that will be the variable to be modified. The result will include a leading space* `[\u20]` *character.*
]