Pronouncing Hex
For those of you uninitiated with the show Silicon Valley, this challenge is inspired by an exchange that goes like this (YouTube):
Kid -
Here it is: Bit… soup. It’s like alphabet soup, BUT… it’s ones and zeros
instead of letters.
Erlich Bachman -
{silence}
Kid -
‘Cause it’s binary? You know, binary’s just ones and zeroes.
Erlich Bachman -
Yeah, I know what binary is. Jesus Christ, I memorized the hexadecimal
times tables when I was fourteen writing machine code. Okay? Ask me
what nine times F is. It’s fleventy-five. I don’t need you to tell me what binary is.
It should be noted that technically, 0x9 * 0xF = 0x87
, not 'fleventy-five', but this brings up an important question - how would you actually pronounce hex in conversation? It's not like oh ex eff eff
flows off the tongue easily, so what should we do? Here's a handy pronunciation chart we will follow.
A = ay A0 = atta-
B = bee B0 = bibbity-
C = cee C0 = city-
D = dee D0 = dickety-
E = ee E0 = ebbity-
F = eff F0 = fleventy-
We can split a 4-length hex number into two groups of two, and determine the pronunciation from the table above, as well as common English pronunciation for numbers. So, for the example 0xFFAB
, we would get Fleventy-eff bitey atta-bee
.
If a number is included, such as 0xF5AB
, you would print Fleventy-five bitey atta-bee
. Also, if a number starts one of the groups, you should use it's "tens" pronunciation. For example, 0x5FAA
would become Fifty-eff bitey atta-ay
. In the case where you have something like 0x1FAC
, this would be Effteen bitey atta-cee
. But, if this rule were to be used for 0x1AF4
, a-teen
could be confused for eighteen
, so you must prepend a Y. So, the correct output would be Yayteen bitey fleventy-four
In the case of 0xD0F4
, instead of doing Dickety-zero bitey fleventy-four
, we would ignore the zero and print Dickety-bitey fleventy-four
.
Hyphens should only appear within the groups of two, i.e. bitey should not be connected to either group with a hyphen unless the first group is only one word! So 0x04F4
would be four-bitey fleventy-four
, but 0x44F4
would be forty-four bitey fleventy-four
. As trichoplax said, bitey should only be hyphened when following a round number.
For a comprehensive look at how this will work, check out the example I/O below.
Objective
Create a program or function that will take a hexadecimal string as input or a function argument and produce it's pronunciation. The output must have proper capitalization. You may assume that the length of this number will always be 4.
Example I/O
"0xFFFF" -> "Fleventy-eff bitey fleventy-eff"
"0x0000" -> "Zero"
"0x0010" -> "Ten"
"0x0100" -> "One-bitey zero"
"0x1110" -> "Eleven-bitey ten"
"0xBEEF" -> "Bibbity-ee bitey ebbity-eff"
"0x9999" -> "Ninety-nine bitey ninety-nine"
"0xA1B2" -> "Atta-one bitey bibbity-two"
"0x3C4F" -> "Thirty-cee bitey forty-eff"
"0x17AB" -> "Seventeen-bitey atta-bee"
"0x1AFB" -> "Yayteen-bitey fleventy-bee"
"0xAAAA" -> "Atta-ay bitey atta-ay"
This is code-golf, so least number of bytes wins.