26
5
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.
6Here's a handy trick for anyone learning the hex times tables: The F times table can be calculated on your 16 fingers and toes (excluding thumbs and big toes). Simply line them up in a row and fold the nth one down to calculate F x n. The number of digits to the left of the folded down digit is the first digit, and the number of digits to the right of the folded down digit is the second digit, allowing you to calculate any 2 digit multiple. For example, fold the Cth digit down to give F x C = Bibbity four. – trichoplax – 2015-07-17T13:51:35.473
2@trichoplax My kid was amazed when I first showed him how to do that for nines on his fingers :D – Geobits – 2015-07-17T13:58:00.557
@Geobits that's what I extrapolated it from - I loved that trick for 9s as a kid. – trichoplax – 2015-07-17T13:58:59.827
@trichoplax I think bitey makes more sense for the purpose of pronunciation. I've tried to make it clearer where hyphens are to appear, and the first letter of the output must be capitalized, and the rest in lowercase. – Kade – 2015-07-17T14:04:44.650
@Geobits I fixed the examples. – Kade – 2015-07-17T14:04:55.087
This pronunciation method takes twice as many syllables than the lerfu (borrowed lojban word for letter pronunciations) themselves, but it is more fun to use. – lirtosiast – 2015-07-19T14:29:37.630
Can we have a leading or trailing space? – George Reith – 2015-07-19T14:55:40.977
@GeorgeReith No extra whitespace should be in the output. – Kade – 2015-07-19T14:56:25.540
Why is
0x17AB
notseventeen-bitey atta-bitey
when the rule is its only hyphenated if the first group is represented by one word? – George Reith – 2015-07-19T17:51:12.657@GeorgeReith seventeen is one word. and I think you mean
atta-bee
– Maltysen – 2015-07-19T20:06:37.3574you don't mention "bitey" anywhere other than examples – Sparr – 2015-07-19T22:24:32.937
@Maltysen Exactly it is one word so it should be hyphenated, i did mean
atta-bee
but the author has since edited the example to correct it. – George Reith – 2015-07-20T09:31:36.793@GeorgeReith sorry, misread your comment. – Maltysen – 2015-07-20T09:33:10.533